I have the follwing MSSQL statement:
SELECT *, YEAR(STARTDATE) AS YEAR
FROM TABLE
WHERE ID = 3438
The result is this:
ID | STARTDATE | VOLUME | YEAR |
---|---|---|---|
3438 | 01-01-2025 | 1000 | 2025 |
3438 | 01-01-206 | 1000 | 2026 |
3848 | 01-01-2027 | 1000 | 2027 |
I would like to produce the following result:
ID | 2025 | 2026 | 2027 |
---|---|---|---|
3438 | 1000 | 1000 | 1000 |
I tried to use the function PIVOT but I can’t seem to make that work. Could be because I am a beginner with SQL.