I have written a small PostgreSQL query that helps me total amount of jobs executed per hourly intervals in every day within two certain dates -e.g. all the jobs executed between February 2, 2012 and March 3, 2012 hour by hour starting with the hour given in February 2 and ending with the hour given in March 3- I have noticed that this query doesn't print the rows with 0 count -no job executed within that time interval e.g. at February 21, 2012 between 5 and 6pm-. How can I make this also return results(rows) with 0 count? The code is as below:
SELECT date_trunc('hour', executiontime), count(executiontime)
FROM mytable
WHERE executiontime BETWEEN '2011-2-2 0:00:00' AND '2012-3-2 5:00:00'
GROUP BY date_trunc('hour', executiontime)
ORDER BY date_trunc('hour', executiontime) ASC;
Thanks in advance.