Currently I have a Oracle table called 'test' and have below data (3 columns):
KEY GROUP VALUE
1 col_1 789
1 col_2 12345
1 col_3 525
1 col_4 ABCD
2 col_1 abc
2 col_2 ds
2 col_3 fg
2 col_4 1234
2 col_5 777
I want to create a new table based on the table 'test' but want the column transpose to row, below is what I expect:
KEY COL1 COL2 COL3 COL4 COL5
1 789 12345 525 ABCD (null)
2 abc ds fg 1234 777
Not every 'Key' has all the 'GROUP' value in the 'test' table. For example, Key 2 has 5 Groups but Key 1 only has 4, I need the new table structure to have all the Groups available for any give Key. If a Key does not have Group value but other Key does, leave the cell as Null.
Can anyone write me a sample query? Thanks!