Daily average for the month (needs number of days in month)
I have a table as follow: CREATE TABLE counts ( T TIMESTAMP NOT NULL, C INTEGER NOT NULL ); I create the following views from it: CREATE VIEW micounts AS SELECT DATE_TRUNC('minute',t) AS t,SUM(c) AS c FROM counts GROUP BY 1; CREATE VIEW hrcounts AS SELECT DATE_TRUNC('hour',t) AS t,SUM(c) AS c,SUM(c)/60 AS a FROM micounts GROUP BY 1; CREATE VIEW dycounts AS SELECT DATE_TRUNC('day',t) AS t,SUM(c) AS c,SUM(c)/24 AS a FROM hrcounts GROUP BY 1; The problem now comes in when I want to create the monthly counts to know what to divide the daily sums by to get the average column a i.e. the number of