I have data like this:
ID | Ref | Value1 | Value2
-----+-----+--------+--------
1 | R1 | 1R11 | 1R12
1 | R2 | 1R21 | 1R22
2 | R1 | 2R11 | 2R12
2 | R2 | 2R21 | 2R22
I want to transform it into this:
ID | R1-Value1 | R1-Value2 | R2-Value1 | R2-Value2
-----+-----------+-----------+-----------+-----------
1 | 1R11 | 1R12 | 1R21 | 1R22
2 | 2R11 | 2R12 | 2R21 | 2R22
This seems at least similar to a pivot to me, but from reading around it doesn't seem like it's something PIVOT
supports. Is that correct, or have I missed something?
Additional: The two main things I'm having trouble with are
- Generating two columns from one row i.e. "R1-Value1" and "R1-Value2" both come from a single row
- I would like the Ref values I query on to be easily changeable. e.g. sometime I want results for R1 and R2, sometimes for R3 and R4 and R5, for a large number of possible combinations.