I am trying to create a SQL Statement to pivot a variable number of rows into a single row. A small subset of the data looks like this:
+--------------+--------+-------+-------+
| ID | Flag | workD | holiD |
+--------------+--------+-------+-------+
| 11155 | N | 1 | 0 |
| 11155 | D | 1 | 1 |
| 5675 | N | 1 | 1 |
| 98761 | N | 0 | 1 |
| 98761 | D | 1 | 1 |
+--------------+--------+-------+-------+
and I would like to pivot the data to look like the following:
+--------------+---------+---------+---------+---------+
| ID | N_wordD | N_holiD | D_wordD | D_holiD |
+--------------+---------+---------+---------+---------+
| 11155 | 1 | 0 | 1 | 1 |
| 5675 | 1 | 1 | NULL | NULL |
| 98761 | 0 | 1 | 1 | 1 |
+--------------+---------+---------+---------+---------+
I am a bit lost when it comes to pivoting, particularly when I want to pivot both the Style and the Quantity into my columns.
Any suggestions, pointers, etc would be greatly appreciated.
