mysql之查詢某段時間範圍的資料

2021-10-19 11:58:25 字數 1230 閱讀 7114

# 查詢今天的資料

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')='2017-07-07';

# 查詢制定時間段內的資料(只寫到月,會出錯)

select * from `user` where birthday between '1888-5-1 00:00:00' and '2017-9-3 00:00:00';

# 查詢制定時間段內的資料(只寫到月,會出錯)

select * from `user` where birthday > '1989-5-1' and birthday < '2017-5-1';

mysql根據時間範圍查詢

select from bank statistics where day time between 2018 06 01 and 2018 06 10 根據兩端範圍查詢 select from bank statistics where day time 2018 05 24 查詢某一天的 sel...

mysql查詢時間範圍

前端傳入的引數確是 yyyy mm dd 的 沒有帶時分秒。如果按照下面這兩種方式會查不全 select from test where create time between 2018 07 30 and 2018 07 31 select from test where create time ...

Mysql查詢時間範圍

sql 今天 select from 表名 where to days 時間欄位名 to days now 昨天 select from 表名 where to days now to days 時間欄位名 1 近7天 select from 表名 where date sub curdate in...