1. 程式人生 > >mysql查詢昨天、明天、近兩天、近三十天等資料

mysql查詢昨天、明天、近兩天、近三十天等資料

select count(*) as num from activity_records where enter_time>=DATE_SUB(NOW(),INTERVAL 5 MINUTE);//5分鐘之內

select count(*) as num from activity_records where enter_time>=DATE_SUB(NOW(),INTERVAL 5 DAY);//5天之內

select count(*) as num from activity_records where enter_time<=NOW();//小於現在

SELECT count(*) as num FROM activity_records WHERE TO_DAYS(NOW())-TO_DAYS(enter_time) = 1 ;//昨天資料

SELECT count(*) as num FROM activity_records WHERE TO_DAYS(enter_time)-TO_DAYS(NOW()) = 1 ;//明天資料

SELECT count(*) as num FROM activity_records where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(enter_time) ;//查詢7sql語句

SELECT count(*) as num FROM activity_records where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(enter_time);//查詢近

30sql語句