generate days from date range

后端 未结 29 2418
渐次进展
渐次进展 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:18

    One more solution for mysql 8.0.1 and mariadb 10.2.2 using recursive common table expressions:

    with recursive dates as (
        select '2010-01-20' as date
        union all
        select date + interval 1 day from dates where date < '2010-01-24'
    )
    select * from dates;
    

提交回复
热议问题