In SQL (AGINITY, Amazon Redshift), I want to group by columns COL1, COL2, and COL3.
Then I want to transpose COL5 so that it will get the sum from COL4.
I think this has to do with converting from long format to wide format. I know how to do it in R but not in SQL. The values are not just A and B by the way. There are about 10 other ones because this is just a subset of many more rows.
I have a dataset as follows:
COL1 COL2 COL3 COL4 COL5
alpha beta gamma 15 A
alpha beta gamma 20 A
alpha beta epsilon 30 A
zeta beta gamma 18 B
zeta delta gamma 13 B
I want to change it to:
COL1 COL2 COL3 A B C D ....
alpha beta gamma 35 0 ... ... ....
alpha beta epsilon 30 0 ... ... ....
zeta beta gamma 0 18 ... ... ....
zeta delta gamma 0 13 ... ... ....
Thanks!