码迷,mamicode.com
首页 > 数据库 > 详细

mysql 获取任意一个月的所有天数。

时间:2018-05-11 10:45:13      阅读:2466      评论:0      收藏:0      [点我收藏+]

标签:一个   SQ   first   sel   interval   nio   rom   day   union all   

SELECT ADDDATE(y.first, x.d - 1) as d
FROM
(
SELECT 1 AS d UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4 UNION ALL
SELECT 5 UNION ALL
SELECT 6 UNION ALL
SELECT 7 UNION ALL
SELECT 8 UNION ALL
SELECT 9 UNION ALL
SELECT 10 UNION ALL
SELECT 11 UNION ALL
SELECT 12 UNION ALL
SELECT 13 UNION ALL
SELECT 14 UNION ALL
SELECT 15 UNION ALL
SELECT 16 UNION ALL
SELECT 17 UNION ALL
SELECT 18 UNION ALL
SELECT 19 UNION ALL
SELECT 20 UNION ALL
SELECT 21 UNION ALL
SELECT 22 UNION ALL
SELECT 23 UNION ALL
SELECT 24 UNION ALL
SELECT 25 UNION ALL
SELECT 26 UNION ALL
SELECT 27 UNION ALL
SELECT 28 UNION ALL
SELECT 29 UNION ALL
SELECT 30 UNION ALL
SELECT 31
) x,
(
SELECT ‘2018-04-05‘ - INTERVAL DAY(‘2018-04-05‘) - 1 DAY AS first,
DAY(LAST_DAY(‘2018-04-05‘)) AS last) y
WHERE x.d <= y.last

mysql 获取任意一个月的所有天数。

标签:一个   SQ   first   sel   interval   nio   rom   day   union all   

原文地址:https://www.cnblogs.com/duanqiao123/p/9023127.html

(2)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!