Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tpitale
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/8908929 to your computer and use it in GitHub Desktop.
Save tpitale/8908929 to your computer and use it in GitHub Desktop.
Group count by creation date and sum of count-to-date.
SELECT created_on, note_count, sum(note_count) OVER (ORDER BY created_on ASC)
FROM (
SELECT date_trunc('day', created_at) AS created_on, count(1) AS note_count
FROM notes
GROUP BY created_on
ORDER BY created_on DESC
) AS note_counting;
-- WHERE created_on >= '2013-01-01'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment