Last active
December 18, 2015 19:09
-
-
Save mgadzhi/5831111 to your computer and use it in GitHub Desktop.
Grouping by month and year in Postgres
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
SELECT CAST(date_part('year', date) AS varchar(4)) || '-' || CAST(date_part('month', date) AS varchar(2)) AS month, SUM(amount) | |
FROM withdrawals | |
WHERE some_predicate() | |
GROUP BY month | |
ORDER BY month; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment