SELECT 
@lastDay := last_day( date_add(@lastDay,interval 1 month ) ) lastDays
from
(SELECT @lastDay := date_add(curdate(),interval -6 month) from application limit 6) a;



SELECT
date_format(@lastDay := last_day( date_add(@lastDay,interval 1 month ) ) ,'%Y-%m' ) lastDays
from
(SELECT @lastDay := date_add(curdate(),interval -6 month) from application limit 6) a;

输出:


mysql 获取最近6个月的日期的 sql 实例_Mysql

image.png

mysql 获取最近6个月的日期的 sql 实例_Mysql_02

image.png