mysql 按年月查询

查询2017的数据:select * from table where year(column)='2017';
查找月份为12的数据:select * from table where month(column)='12';
查找天数为本年第二天的数据:select * from table where dayofyear(column)='2';

year,month,dayofyear是mysql的函数,分别是取得年,月,和当前时间在本年是第几天的3个函数

查询当月数据:select * from table
where date_format(column,'%Y-%m')=date_format(now(),'%Y-%m')

原文地址:https://www.cnblogs.com/-xuzhankun/p/7388755.html