-
-
Save hbasria/7b9387dabdfd2f963e44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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