generate days from date range

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

    A more generic answer that works in AWS MySQL.

    select datetable.Date
    from (
        select date_format(affffdate(now(),-(a.a + (10 * b.a) + (100 * c.a))),'%Y-%m-%d') AS Date
        from (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
    ) datetable
    where datetable.Date between now() - INTERVAL 14 Day and Now()
    order by datetable.Date DESC
    

提交回复
热议问题