今天
select
*from 表名 where to_days(時間欄位名) = to_days(now());
昨天
select
*from 表名 where to_days( now( ) ) - to_days( 時間欄位名) <=1
近
7天
select
*from 表名 where date_sub(curdate(), interval7day) <= date(時間欄位名)
近
30天
select
*from 表名 where date_sub(curdate(), interval30day) <= date(時間欄位名)
本月
select
*from 表名 where date_format( 時間欄位名, '%y%m' ) = date_format( curdate( ) , '%y%m' )
上一月
select
*from 表名 where period_diff( date_format( now( ) , '%y%m' ) ,date_format( 時間欄位名, '%y%m' ) ) =1
查詢本季度資料
select
*from `ht_invoice_information` where quarter(create_date)=quarter(now());
查詢上季度資料
select
*from `ht_invoice_information` where quarter(create_date)=quarter(date_sub(now(),interval1quarter));
查詢本年資料
select
*from `ht_invoice_information` where
year(create_date)=
year(now());
查詢上年資料
select
*from `ht_invoice_information` where
year(create_date)=
year(date_sub(now(),interval1year));
查詢當前這週的資料
select name,submittime fromenterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now());
查詢上週的資料
select name,submittime fromenterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1;
查詢上個月的資料
select name,submittime fromenterprise where date_format(submittime,'%y-%m')=date_format(date_sub(curdate(), interval1month),'%y-%m')
select
*from
user
where date_format(pudate,'%y%m') = date_format(curdate(),'%y%m') ;
select
*from
user
where weekofyear(from_unixtime(pudate,'%y-%m-%d')) = weekofyear(now())
select
*from
user
where
month(from_unixtime(pudate,'%y-%m-%d')) =
month(now())
select
*from
user
where
year(from_unixtime(pudate,'%y-%m-%d')) =
year(now()) and
month(from_unixtime(pudate,'%y-%m-%d')) =
month(now())
select
*from
user
where pudate between 上月最後一天 and 下月第一天
查詢當前月份的資料
select name,submittime fromenterprise wheredate_format(submittime,'%y-%m')=date_format(now(),'%y-%m')
查詢距離當前現在
6個月的資料
select name,submittime fromenterprise where submittime betweendate_sub(now(),interval6month) and now();
查詢當年當月資料
select from tbl category t where t.creationtime trunc sysdate,mm and t.creationtime last day sysdate select trunc sysdate,mm tm from tbl category sele...
mysql 查詢當天當周當月的資料
1 查詢當天的資料 select from 表名 where to days 時間字段 to days now 2 查詢當周的資料 select from 表名 where yearweek date format 時間字段,y m d yearweek now 3 查詢當月的資料 select f...
sql查詢當天 當月 當年
今天 select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days 時間欄位名 1 近7天select from 表名 where date sub curdate interval...