I’m writing a report that needs to display a value per day. I have the start and end date for the query, but I wish to avoid missing days in case the table does not contain a value for a specific date.
I was thinking about creating a base date range table that holds all days between start and end, then left join it with the data table to show a value for each day.
I found a few scripts for mySQL, SQL Server, etc.. but none for SQLite.
Is there a way to quickly populate a table with a date range?
Thanks
Here’s how you could use a numbers table to expand a range:
In this case, the numbers table is supposed to hold numbers starting from 0.
A numbers table is a tool worth keeping handy for many purposes. You could initialise it like this, for instance:
Every line
#Nresults in 2N rows in the table, the largest number being2N-1A demonstration of the method can be found (and played with) on SQL Fiddle.