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语句 


你可能感兴趣的:(mysql查询昨天、明天、近两天、近三十天等数据)