今天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 7 day) <= date(時間欄位名)
近30天
select * from 表名 where date_sub(curdate(), interval 30 day) <= 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(),interval 1 quarter));
#查詢本年資料
select * from `ht_invoice_information` where year(create_date)=year(now());
#查詢上年資料
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
查詢當前這週的資料
select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now());
查詢上週的資料
select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1;
查詢當前月份的資料
select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(now(),'%y-%m')
查詢距離當前現在6個月的資料
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查詢上個月的資料
select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(date_sub(curdate(), interval 1 month),'%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 下月第一天
where date(regdate) = curdate();
select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())
select date( c_instime ) ,curdate( )
from `t_score`
where 1
limit 0 , 30
MySQL中按天 自然周 月 季度 年份統計
在oracle資料庫中,通過to char 函式來操作日期變數,而在mysql中,則通過date format 函式實現日期相關週期的統計。date format 函式一共有兩個引數 date引數表示日期變數,format引數表示日期格式。如果想檢視date format 函式的具體引數及其取值情況...
mysql 查詢統計近7天記錄
有需求查詢近7天 每天的訪問量的需求 1 統計7天所有的訪問記錄 select date format c.addtime,y m d days,count count from select from contentmessage where date sub curdate interval 7...
mysql查詢今天 昨天 7天 近30天 本月資料
今天 select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days 時間欄位名 1 datediff now from unixtime 時間欄位名 1 時間字段 儲存型別為時間戳 ...