MySQL查询当天、最近几天数据

1.查询当天数据:

SELECT * FROM issue_log WHERE issue_time_ LIKE CONCAT(SUBSTR(SYSDATE(),1,10),'%')

2.查询最近12天数据:

SELECT * FROM overrun_warning WHERE DATE_SUB(CURDATE(),INTERVAL 11 DAY)<=DATE(WARNING_TIME_)

用到的函数:DATE_SUB(date,INTERVAL expr unit)

3.查询本月数据:

SELECT * FROM issue_log WHERE issue_time_ LIKE CONCAT(SUBSTR(SYSDATE(),1,7),'%')

4.查询上月数据:

SELECT * FROM show_info WHERE PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(TIME_COLL_,'%Y%m'))=1

5.查询去年数据:

SELECT * FROM show_info WHERE PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%'),DATE_FORMAT(TIME_COLL_,'%Y%'))=1

 

你可能感兴趣的:(MySQL)