代码:
SELECT DATE_ADD(start_date, INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY) AS `date` FROM (SELECT '2024-02-24' AS start_date, '2024-03-11' AS end_date) AS input CROSS JOIN ( SELECT 0 AS a UNION ALL SELECT 1 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 ) AS a CROSS JOIN ( SELECT 0 AS a UNION ALL SELECT 1 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 ) AS b CROSS JOIN ( SELECT 0 AS a UNION ALL SELECT 1 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 ) AS c WHERE DATE_ADD(start_date, INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY) <= end_date
效果图:
标签:JOIN,start,UNION,CROSS,便于,时间段,mysql,date,SELECT From: https://www.cnblogs.com/dfym80/p/18128179