https://www.cnblogs.com/zhangliang88/p/5479682.html
查从昨天起 到一年前的数据 sql
select * from test where 字段名 between DATE_SUB(NOW(), INTERVAL 365 DAY) and DATE_SUB(NOW(), INTERVAL 1 DAY)
通过sql语句查询与当前时间相隔5分钟以内的数据
select * from 数据表名 where 字段名 between date_add(now(), interval - 5 minute) and now();
查询2011的数据:select * from 表 where year(date)='2011';
查找月份为12的数据:select * from 表 where month(date)='12';
查找天数为本年第二天的数据:select * from 表 where dayofyear(date)='2';
我解释一下:
select * from 表 where 这是必须的
year,month,dayofyear是mysql的函数,分别是取得年,月,和当前时间在本年是第几天的3个函数
date就是你保存时间的字段