用年月啊,把年份带出来,用的时候用月份不就好了
mysql
-------------------
SELECT
@s :=@s - 1 as `index`,
DATE_FORMAT(DATE_add(date_sub(CURDATE(),interval 1 month), INTERVAL @s MONTH),'%Y-%m') AS `ymon`,
DATE_FORMAT(DATE_add(date_sub(CURDATE(),interval 1 month), INTERVAL @s MONTH),'%m') AS `mon`
FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4)T1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3)T2,
(SELECT @s := 1) temp
WHERE
@s < 13
-------------------------
年月都有不就好判断了!