I have a table that looks like below:
+——+——+———-+———-+——-+
|Period| Col1 | Col2 | Col3 | Col4 |
+——+——+———-+———-+——-+
|202401| 10 | 10 | 200 | 1 |
|202401| 15 | 12 | 200 | 10 |
|202402| 20 | 10 | 300 | 10 |
|202402| 20 | 12 | 300 | 10 |
+——+——+———-+———-+——-+
I need to get the SUM(Column Value) group by Period and transforming the clolumns into rows:
+——+——+———-+
| Name |Period| Value |
+——+——+———-+
| Col1 |202401| 25 |
| Col1 |202402| 40 |
| Col2 |202401| 22 |
| Col2 |202402| 22 |
| Col3 |202401| 400|
| Col3 |202402| 600|
| Col4 |202401| 11 |
| Col4 |202402| 20 |
+——+——+———-+
How can this be achieved via SQL.
I’m using MS SQL Server 20219.