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) ;//查询7天 sql语句

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


 ———————————————— 
 

你可能感兴趣的:(web后端)