一、月份(1,2,3,4,5,6,7,8,9,10,11,12)
SELECT
DATE_FORMAT( CURDATE( ), '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 1 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 2 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 3 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 4 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 5 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 6 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 7 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 8 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 9 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 10 MONTH, '%c' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 11 MONTH, '%c' ) AS MONTH
更简洁的写法:
SELECT
1 AS MONTH UNION
SELECT
2 AS MONTH UNION
SELECT
3 AS MONTH UNION
SELECT
4 AS MONTH UNION
SELECT
5 AS MONTH UNION
SELECT
6 AS MONTH UNION
SELECT
7 AS MONTH UNION
SELECT
8 AS MONTH UNION
SELECT
9 AS MONTH UNION
SELECT
10 AS MONTH UNION
SELECT
11 AS MONTH UNION
SELECT
12 AS MONTH
运行结果:
二、月份(01,02,03,04,05,06,07,08,09,10,11,12)
SELECT
DATE_FORMAT( CURDATE( ), '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 1 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 2 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 3 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 4 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 5 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 6 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 7 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 8 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 9 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 10 MONTH, '%m' ) AS MONTH UNION
SELECT
DATE_FORMAT( CURDATE( ) - INTERVAL 11 MONTH, '%m' ) AS MONTH
更简洁的写法:
SELECT
01 AS MONTH UNION
SELECT
02 AS MONTH UNION
SELECT
03 AS MONTH UNION
SELECT
04 AS MONTH UNION
SELECT
05 AS MONTH UNION
SELECT
06 AS MONTH UNION
SELECT
07 AS MONTH UNION
SELECT
08 AS MONTH UNION
SELECT
09 AS MONTH UNION
SELECT
10 AS MONTH UNION
SELECT
11 AS MONTH UNION
SELECT
12 AS MONTH
运行结果: