Convert query from MySql to Sqlite

前端 未结 2 1743
忘了有多久
忘了有多久 2021-01-26 14:59

I need to convert this query from MySQL format to SQLite. I\'m trying myself but I\'ve found some difficulty.

In SQLite, the curdate() and the interval functions do not

相关标签:
2条回答
  • 2021-01-26 15:15

    What this query actually does is just generating lots of consecutive dates (up to one thousand previous days).

    In SQLite 3.8.3 or later, this can be done more easily with a recursive common table expression:

    WITH RECURSIVE dates(d)
    AS (VALUES('2010-01-20')
        UNION ALL
        SELECT date(d, '+1 day')
        FROM dates
        WHERE d < '2010-01-24')
    SELECT d AS date FROM dates;
    
    0 讨论(0)
  • 2021-01-26 15:19

    Here is the basic syntax:

    select a.Date 
    from (select date('now', '-'||(a.a + (10 * b.a) + (100 * c.a))|| ' days') 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
               ) 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
               ) 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
               ) c
        ) a;
    

    I left out the where clause because those dates are more than 1000 days in the past, so they won't select anything anyway.

    0 讨论(0)
提交回复
热议问题