dynamic Pivot or Transpose
Hi,
I have a dataset like the following;
groupid | time_stamp | consumption |
A1 | 201501 | X1 |
A1 | 201503 | X2 |
A1 | 201505 | X3 |
A1 | 201506 | X4 |
B1 | 201502 | X5 |
B1 | 201503 | X6 |
B1 | 201505 | X7 |
B1 | 201506 | X8 |
B1 | 201507 | X9 |
and I would like to convert the dataset to
groupid | T_201501 | T_201502 | T_201503 | T_201505 | T_201506 | T_201507 |
A1 | X1 | X2 | X3 | X4 | ||
B1 | X5 | X6 | X7 | X8 | X9 |
max(decode) works perfectly, I can pivot the table as desired.
But the problem is in our dataset we have 144 distinct "time_stamp"s, which means we need to write max(code) statement 144 times.
Is there a way we can dynamically populate the max(decode) lines and pivot or transpose the table.
Thanks
0