SQL - Convert data from Columns into Rows - UNPIVOT

 Please watch the below YouTube video for complete explanation.

https://www.youtube.com/watch?v=mf4ABpHqgag&list=PL2-GO-f-XvjBl5fpzdfYaPW28PwsLzLc4&index=26

Please find below the SQL Query -

Select Category, Year, Sales from 

( Select Category, [2015], [2016], [2017], [2018], [2019], [2020]

from dbo.Sales ) OrigSales

UNPIVOT

(Sales FOR YEAR IN ([2015], [2016], [2017], [2018], [2019], [2020])

) as UNPIVT_SALES

Post a Comment

Previous Post Next Post

Contact Form