Last active
November 25, 2019 12:53
-
-
Save keepingcoding/f0be17e49965052fa27bc36e20acbd67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### MYSQL获取一整月的日期列 | |
## 第一种 | |
SELECT | |
date_list, | |
CASE | |
DAYOFWEEK( date_list ) | |
WHEN 1 THEN | |
'星期日' | |
WHEN 2 THEN | |
'星期一' | |
WHEN 3 THEN | |
'星期二' | |
WHEN 4 THEN | |
'星期三' | |
WHEN 5 THEN | |
'星期四' | |
WHEN 6 THEN | |
'星期五' | |
WHEN 7 THEN | |
'星期六' | |
END week_name | |
FROM | |
( | |
SELECT | |
date_add( curdate( ), INTERVAL t.help_topic_id DAY ) AS date_list | |
FROM | |
mysql.help_topic t | |
WHERE | |
t.help_topic_id < DAY ( last_day( curdate( ) ) ) | |
) t1; | |
## 第二种 | |
SELECT DATE_FORMAT(DATE_SUB(LAST_DAY(NOW()), INTERVAL xc-1 DAY), '%Y-%m-%d') as date | |
FROM | |
( | |
SELECT @xi:=@xi+1 as xc from | |
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) xc1, | |
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc2, | |
(SELECT @xi:=0) xc0 | |
) xcxc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment