I have the following output from a sql query in a row. I'd like to pivot the row values to a single column labeled id:
| id | lag_1 | lag_2 | lag_3 |
| -- | ----- | ----- | ----- |
| 8 | 7 | 6 | 5 |
expected output:
id
8
7
6
5
I have the following output from a sql query in a row. I'd like to pivot the row values to a single column labeled id:
| id | lag_1 | lag_2 | lag_3 |
| -- | ----- | ----- | ----- |
| 8 | 7 | 6 | 5 |
expected output:
id
8
7
6
5
This is known as "unpivot". Different database platforms have different methods available to accomplish. MySQL uses UNION construct to rearrange fields to rows.
Remove ALL if you don't want duplicates.