一、MYSQL查詢最近的三個月份的簡便方法:
select date_format(curdate(),'%Y-%m') from dual union select date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m') from dual union select date_format(DATE_SUB(curdate(), INTERVAL 2 MONTH),'%Y-%m') from dual

二、sql查詢兩個日期內的所有日期
select * from (select @num:=@num+1,date_format(adddate('2018-03-11', INTERVAL @num DAY),'%Y-%m-%d') as date from user_attendance,(select @num:=0) t where adddate('2018-03-11', INTERVAL @num DAY) <= date_format('2018-03-15','%Y-%m-%d') order by date )a
注意有個前提:必須要有一個表,它的數據條數大到足夠支撐你要查詢的天數