My database table is such that each entry is listed in a new row for each chart. I want to 'pivot' and group by ID. Do I need to use a bunch of CASE WHEN
statements or is this a succinct way of doing this?
Here's a simplified table:
Chart_ID | Rule | Action |
---|---|---|
A1 | R1 | Y |
A1 | R3 | N |
B4 | R1 | N |
C1 | R1 | Y |
C1 | R2 | N |
C1 | R3 | Y |
I'd like a table like this:
Chart_ID | R1 | Action1 | R2 | Action2 | R3 | Action3 | R4 | Action4 |
---|---|---|---|---|---|---|---|---|
A1 | R1 | Y | R3 | N | ||||
B4 | R1 | N | ||||||
C1 | R1 | Y | R2 | N | R3 | Y |