1、查询当天的数据
select * from order_1 where
to_days(order_time)=to_days(now());
2、查询昨天的数据
select * from order_1 where
to_days(now())-to_days(order_time) =1;
3、查询最近7天的数据(包括今天一共7天)
select * from order_1 where
date_sub(curdate(),interval 7 day) < date(order_time);
4、查询最近30天的数据(包括今天一共30天)
select * from order_1 where
date_sub(curdate(),interval 30 day) < date(order_time);
5、查询当月(本月)的数据
select * from order_1 where
date_format(curdate(),’%y%m’) = date_format(order_time,’%y%m’);
6、查询上个月的数据
select * from order_1 where
period_diff(date_format(now(),’%Y%m’),date_format(order_time,’%Y%m’))=1;
7、查询本季度的数据
select * from order_1 where
quarter(order_time) = quarter(now());
8、查询上季度的数据
select * from order_1 where
quarter(order_time) =quarter(date_sub(curdate(),interval 1 quarter));
9、查询当年(今年)的数据
select * from order_1 where
year(order_time) = year(now());
10、查询去年的数据
select * from order_1 where
year(order_time) = year(date_sub(now(),interval 1 year));
11、查询当前这周的数据
select * from order_1 where
yearweek(date_format(order_time, ‘%Y-%m-%d’),1) = yearweek(now(),1);
12、查询上周的数据
select * from order_1 where
yearweek(date_format(order_time, ‘%Y-%m-%d’),1) = yearweek(now(),1)-1;
13、查询距离当前现在6个月的数据
select * from order_1 where
order_time between date_sub(now(),interval 6 month) and now();