– 查詢今天的資料
select
*from
`user
`where to_days(birthday)
= to_days(curdate())
;
– 查詢昨天的資料
select
*from
`user
`where to_days(curdate())
- to_days(birthday)
<=
1;
– 查詢最近7天的資料
select
*from
`user
`where birthday > date_sub(curdate(),
interval
7day
);
–查詢本月的資料
select
*from
`user
`where date_format( birthday ,
'%y%m'
)= date_format( curdate(),
'%y%m'
)
– 查詢最近乙個季度的資料
select
*from
`user
`where birthday > date_sub(curdate(),
interval
3month
)
– 最近一年的資料
select
*from
`user
`where birthday > date_sub(curdate(),
interval
1year
);
– 本季度的資料
select
*from
`user
`where quarter(birthday)
= quarter(curdate())
;
– 上季度的資料
select
*from
`user
`where quarter(birthday)
= quarter(date_sub(curdate(),
interval
1 quarter)
);
– 查詢今年的資料
select
*from
`user
`where
year
(curdate())
-year
(birthday)=28
;
– 查詢第幾月的資料
select
*from
`user
`where
month
(birthday)=8
;
– 查詢某年某月某日的資料
select
*from
`user
`where date_format(birthday,
'%y-%m-%d')=
'2017-07-07'
;
– 查詢制定時間段內的資料(只寫到月,會出錯)
select
*from
`user
`where birthday between
'1888-5-1 00:00:00'
and'2017-9-3 00:00:00'
;
– 查詢制定時間段內的資料(只寫到月,會出錯)
select
*from
`user
`where birthday >
'1989-5-1'
and birthday <
'2017-5-1'
;
– 查詢當天的所有資料
select
*from 表名 where datediff(字段,
now())
=0
– 查詢昨天的所有資料
select
*from 表名 where datediff(字段,
now())
=-1
MySQL查詢某時間範圍的資料
查詢今天的資料 select from user where to days birthday to days curdate 查詢昨天的資料 select from user where to days curdate to days birthday 1 查詢最近 7 天的資料 select f...
MySQL 查詢某時間範圍的資料
查詢今天的資料 select from user where to days birthday to days curdate 查詢昨天的資料 select from user where to days curdate to days birthday 1 查詢最近7天的資料 select fro...
oracle 查詢大於某時間點的資料
查詢的結果,要求某列大於某個時間點的記錄。tablename 表名 columnname 列名 select from tablename where columnname to date 2020 7 31 09 40 00 yyyy mm dd hh24 mi ss select from ta...