美文网首页
生成过去15天(包括今天)的日期

生成过去15天(包括今天)的日期

作者: 苍老师的眼泪 | 来源:发表于2021-01-04 01:23 被阅读0次
    select last14.Date from (       
                select curdate() - INTERVAL (last14.last14) DAY as Date     from (  select  0   as  last14  
                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             union all select 10
                union all select 11            union all select 12            union all select 13            union all select 14            ) as last14
    ) as last14;
    

    过去10000天:

    select a.Date 
    from (
        select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a) + (1000 * d.a) ) DAY 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
        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 d
    ) a
    where a.Date between '2010-01-20' and '2010-01-24' 
    

    https://stackoverflow.com/questions/2157282/generate-days-from-date-range/2157776#2157776

    相关文章

      网友评论

          本文标题:生成过去15天(包括今天)的日期

          本文链接:https://www.haomeiwen.com/subject/wolmoktx.html