Let's say I have a search like this:
SELECT COUNT(id), date(created_at) FROM entries WHERE date(created_at) >= date(current_date - interval '1 week') GROUP BY date(created_at)
As you know, for example, I return the result as follows:
count | date 2 | 15.01.2014 1 | 13.01.2014 9 | 09.01.2014
But I do not get days of the week where there are no entries that were created.
How can I get a search result that looks like this: including days when there are no entries that were created?
count | date 2 | 15.01.2014 0 | 14.01.2014 1 | 13.01.2014 0 | 12.01.2014 0 | 11.01.2014 0 | 10.01.2014 9 | 09.01.2014
sql aggregate-functions postgresql generate-series
John Smith Mar 31 '15 at 6:53 2015-03-31 06:53
source share