查询当前这周的数据
SELECT name,create_date FROM sta_statistics_count WHERE YEARWEEK(date_format(create_date,'%Y-%m-%d')) = YEARWEEK(now());
查询上周的数据
SELECT name,create_date FROM sta_statistics_count WHERE YEARWEEK(date_format(create_date,'%Y-%m-%d')) = YEARWEEK(now())-1;
查询当前月份的数据
select name,create_date from sta_statistics_count where date_format(create_date,'%Y-%m')=date_format(now(),'%Y-%m')
查询距离当前现在6个月的数据
select name,create_date from sta_statistics_count where create_date between date_sub(now(),interval 6 month) and now();
查询上个月的数据
select name,create_date from sta_statistics_count where date_format(create_date,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
MySQL查询本周、上周、本月、上个月份数据的sql代码
最新推荐文章于 2024-07-17 01:10:25 发布