mapper SQL常用天/周/月时间范围写法
1.统计今天数据
and to_days(create_time) = to_days(now())
2.统计本周
YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
2.1 统计上周
YEARWEEK(date_format(t.create_time,'%Y-%m-%d'),1) = YEARWEEK(DATE_ADD(now(), INTERVAL -7 DAY),1)
3.统计本月
date_format(create_time,'%Y-%m')=date_format(now(),'%Y-%m')
4.近7天
create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)