赞
踩
-- 查询今天的数据
select * from `user` where to_days(birthday) = to_days(CURDATE());
-- 查询昨天的数据
select * from `user` where to_days(CURDATE()) - to_days(birthday)<=1;
-- 查询最近 7 天的数据
select * from `user` where birthday > DATE_SUB(CURDATE(),INTERVAL 7 DAY);
-- 查询最近一个季度的数据
select * from `user` where birthday > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
-- 最近一年的数据
select * from `user` where birthday > DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
-- 本季度的数据
select * from `user` where quarter(birthday) = quarter(CURDATE());
-- 上季度的数据
select * from `user` where quarter(birthday) = quarter(DATE_SUB(CURDATE(), INTERVAL 1 QUARTER));
-- 查询今年的数据
select * from `user` where year(CURDATE()) - year(birthday) = 28 ;
-- 查询第几月的数据
select * from `user` where month(birthday) = 8 ;
-- 查询某年某月某日的数据
select * from `user` where date_format(birthday,'%Y-%m-%d')='2020-07-07';
-- 查询制定时间段内的数据(只写到月,会出错)
select * from `user` where birthday between '2020-5-1 00:00:00' and '2020-9-3 00:00:00';
-- 查询制定时间段内的数据(只写到月,会出错)
select * from `user` where birthday > '2020-5-1' and birthday < '2020-5-1';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。