I need to realize a pivot table in Postgres, but I have no idea how to do it. The function to use should be the crosstab()
, but I'm not sure I know how to use it properly.
Given a table like this:
column a | column b | column c | value 1 | value 2
0 |
1 |
2 |
3 |
4 |
I have to get something like this:
column c | Column b | 0 | 1 | 2 | 3 | 4
| |value 1|value 1|value 1|value 1|value 1|
| |
So I need to get the row 0, ... , 4 as columns, and value 1
as values. crosstab()
function wants 3 columns, nut I need column c
and column b
both to appear.