Created
December 17, 2014 18:41
-
-
Save hgmnz/111962fcb1068f8df8d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH weeks AS ( | |
SELECT distinct date_trunc('week', dates)::date AS start, | |
daterange(date_trunc('week', dates)::date, (date_trunc('week', dates) + interval '7 days')::date) week | |
FROM generate_series(date '2013-01-01', now(), '1 day') | |
dates ORDER BY 1 | |
) | |
SELECT weeks.start, | |
count(whatever.*) as count | |
FROM whatever | |
JOIN weeks | |
ON weeks.week @> whatever.created_at::date | |
GROUP BY 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or