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
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;
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.