How To Unpivot In SQL Server With Example
Given the following records below, you may want to show them in a vertical manner instead of horizontal view of columns.
To achieve the desired result, you use UNPIVOT clause in your query.
Screenshot
1 2 3 4 5 6 7 8 | Use testdatabase Go SELECT [Subject], Grade FROM StudentReportCard UNPIVOT (Grade FOR [Subject] IN (English, Math, Literature, Biology)) AS U_SubjectGrade WHERE StudentId = 1 |
Comments
Post a Comment