I have a KVP Table and the structure is ID, Key, Value.
Here are some example values…
ID, KEY, VALUE
---------------------
1, STATUS, TRUE
1, AGE GROUP, 10
1, TRAVEL, Y
2, STATUS, FALSE
2, AGE GROUP, 20
2, TRAVEL, N
I want these values to be transformed as below…
ID, STATUS, AGE GROUP, TRAVEL
------------------------------
1, TRUE, 10, Y
2, FALSE, 20, N
I have read about crosstab/pivot, but I’m not able to make a query which can give me the above output. Is there any way in SQL to make my output look like the above example?
There are probably optimizations, but this works (tested in SQLite and MySQL)
Edited to fix a possible ambiguity.