I have the following table format:
ID | Key | Value
-- --- -----
1 A aa
2 B bb
3 A ay
4 C cc
5 B bx
6 C ct
I need to convert this table to following format:
Output:
A B C
--- --- ---
aa bb cc
ay bx ct
I looked for PIVOT function in oracle 11g, but the "Key" values in input table is not a fixed set of values, they can be anything. I also looked for other such questions but I am not sure in my case, how the query should be written.
Any help will be appreciated, thanks!
Edited:
For the solution, I want to execute the following query but it gives me error at subquery of IN clause. I don't understand why is that.
Select * from (Select Key, Value, Id from tableName
pivot (max(Value) for Key IN (SELECT distinct Key from tableName)));
Thanks!