SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,437 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a table as below
Account | Jan | Feb | March | April | May | June |
---|---|---|---|---|---|---|
41000000 | 100 | 350 | 200 | 450 | 120 | 900 |
90881233 | 120 | 900 | 340 | 230 | 129 | 300 |
How can I transpose it to be like the below
Account | Month | Total |
---|---|---|
41000000 | Jan | 100 |
41000000 | Feb | 350 |
41000000 | March | 200 |
41000000 | April | 450 |
41000000 | May | 120 |
41000000 | June | 900 |
90881233 | Jan | 120 |
90881233 | Feb | 900 |
90881233 | March | 340 |
90881233 | April | 230 |
90881233 | May | 129 |
90881233 | June | 300 |
For this you can use the build-in SQL feature UNPIVOT, see FROM - Using PIVOT and UNPIVOT