Created
October 4, 2012 16:37
-
-
Save robertsosinski/3834827 to your computer and use it in GitHub Desktop.
Example crosstab function
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 c.id, c.name, c.jan, c.feb, c.mar | |
FROM crosstab( | |
'select buyers.id, buyers.name, transactions.month, sum(transactions.amount) from transactions inner join buyers on buyers.id = transactions.buyer_id group by buyers.id, buyers.name, transactions.month order by buyers.id, transactions.month', | |
'select generate_series(1, 3)' | |
) c (id integer, name character varying, jan numeric(12,2), feb numeric(12,2), mar numeric(12,2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment