I am working with SQLite.
Suppose I have a table sales
with two columns, date
and count
, to keep track of how many glasses of lemo
Create a calendar table and join onto that:
Something like this will do:
create table dates (id integer primary key);
insert into dates default values;
insert into dates default values;
insert into dates select null from dates d1, dates d2, dates d3 , dates d4;
insert into dates select null from dates d1, dates d2, dates d3 , dates d4;
alter table dates add date datetime;
update dates set date=date('2000-01-01',(-1+id)||' day');
That will cover you till 2287-05-20 Adding an index to the date column in the dates table won't hurt. My sqlite is little rusty, so I suggest you consult the manual on that.
Edit: Code for the index:
create unique index ux_dates_date on dates (date);