How can I convert dynamically a key-value table using Case without specifying row names?
For example I have this table named key_value
:
id key value
1 name john
2 fname akbar
3 jobs Software enginer
. . .
. . .
. . .
. . .
. . .
n n n
I want to convert all these rows dynamically to columns without specifying key name like:
name fname jobs............................n
john akbar sofware engineer...........n
I have used:
Max(Case WHEN key='name' THEN value END) AS name
In this query I know my key.
What if I don't know my fields and I don't know how many fields I have?
I want to convert all of this dynamically without specifying my fields.