mysql查詢昨天、明天、近兩天、近三十天等資料
阿新 • • 發佈:2019-01-27
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) ;//查詢7天 sql語句
SELECT count(*) as num FROM activity_records where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(enter_time);//查詢近