mysql 获取最近6个月的日期的 sql 实例
2018-08-31 本文已影响14人
光剑书架上的书
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;
输出:
image.png image.png