generate days from date range

后端 未结 29 2479
渐次进展
渐次进展 2020-11-21 05:19

I would like to run a query like

select ... as days where `date` is between \'2010-01-20\' and \'2010-01-24\'

And return data like:

29条回答
  •  情歌与酒
    2020-11-21 06:03

    Shorter than accepted answer, same idea:

    (SELECT TRIM('2016-01-05' + INTERVAL a + b DAY) date
    FROM
    (SELECT 0 a UNION SELECT 1 a UNION SELECT 2 UNION SELECT 3
    UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7
    UNION SELECT 8 UNION SELECT 9 ) d,
    (SELECT 0 b UNION SELECT 10 UNION SELECT 20
    UNION SELECT 30 UNION SELECT 40) m
    WHERE '2016-01-05' + INTERVAL a + b DAY  <=  '2016-01-21')
    

提交回复
热议问题