原文:http://www.open-open.com/code/view/1423207309170
select * from ad_proTrack_t where to_days(crt_time) = to_days(now()); //今天做测试的时候调用到了这句sql,发现不是想要的结果。 经过尝试发现,to_days函数括号内的‘时间字段’不能加引号,加引号的转换后为NULL 查询昨天的信息记录: select * from ad_proTrack_t where to_days(now()) – to_days(crt_time) <= 1; 查询近7天的信息记录: select * from ad_proTrack_t where date_sub(curdate(), INTERVAL 7 DAY) <= date(crt_time); 查询近30天的信息记录: select * from ad_proTrack_t where date_sub(curdate(), INTERVAL 30 DAY) <= date(crt_time); 查询本月的信息记录: select * from ad_proTrack_t where date_format(crt_time, ‘%Y%m‘) = date_format(curdate() , ‘%Y%m‘); 查询上一月的信息记录: select * from ad_proTrack_t where period_diff(date_format(now() , ‘%Y%m‘) , date_format(crt_time, ‘%Y%m‘)) =1;
时间: 2024-10-24 17:49:41