I have a query that returns an entire row and I need to pivot this result into a new table.
SELECT id_no, stud_name, group_no, class_1, class_2, class_3, class_4 FROM tbl_stud_class
This returns the following:
| id_no | stud_name | group_no | class_1 | class_2 | class_3 | class 4 |
| 1 | John Doe | A11 | 84 | 60 | 80 | 79 |
I need to be able to return this row as:
| id_no | stud_name | group_no | class | grade |
| 1 | John Doe | A11 | class_1 | 84 |
| 1 | John Doe | A11 | class_2 | 60 |
| 1 | John Doe | A11 | class_3 | 80 |
| 1 | John Doe | A11 | class_4 | 79 |
Can someone point me to a way to do this please? I am converting my PostgreSQL function (where i'm using CROSS JOIN LATERAL to SQL Server)
Thank you!