Question

I'm building a complex query but I have a problem... Pratically, I retrieve a dates range from recursive function in sqlite:

WITH RECURSIVE dates(d)
AS (VALUES('2014-05-01')
    UNION ALL
    SELECT date(d, '+1 day')
    FROM dates
    WHERE d < '2014-05-5')
SELECT d AS date FROM dates

This is the result:

2014-05-01
2014-05-02
2014-05-03
2014-05-04
2014-05-05

I would join this query on other query, about this:

select date_column, column1, column2 from table

This is the result:

2014-05-03  column_value1  column_value2

Finally, I would like to see a similar result in output (join first query and date_column of second query):

2014-05-01 |               |               |
2014-05-02 |               |               |
2014-05-03 | column_value1 | column_value2 |
2014-05-04 |               |               |
2014-05-05 |               |               |

How can I obtain this result?

Thanks!!!

Was it helpful?

Solution

Why don't you simply do something like this ?

WITH RECURSIVE dates(d)
AS (VALUES('2014-05-01')
    UNION ALL
    SELECT date(d, '+1 day')
    FROM dates
    WHERE d < '2014-05-5')
SELECT 
    dates.d AS date 
    ,table.column1
    ,table.column2
FROM dates
    left join table
        ON strftime("%Y-%m-%d", table.date_column) = dates.date

Perhaps you will need to convert your date...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top