How do I pivot data (from long to wide), sum by ID, while merging duplicates in SQL

You need to “FEED” your pivot with only the required columns


select * 
 from  ( Select ID
          From  YourTable
       ) src
 pivot (sum(Dollars) for year in ([2017], [2018], [2019])) pvt

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top