mysql 查询指定年/月份的数据

319 阅读1分钟

1、表数据结构如下

2、查询2018年的数据:

 select * from day_rate where year(date)='2018'

3、查询2月份的数据:

select * from day_rate where month(date)='02'

4、查询2019年2月份的数据:

select * from day_rate where year(date)='2019' and month(date)='02'

5、查询年初第32天的数据:

select * from day_rate where dayofyear(date)='32'

6.查询2019年2月01日的数据

SELECT * FROM day_rate WHERE YEAR(date)='2019' AND MONTH(date) ='02' AND DAY(date) ='01'