Summarize aggregated data

前端 未结 5 1821
挽巷
挽巷 2021-01-13 14:27

I have a table like as follows:

SoftwareName    Count    Country
Project         15       Canada
Visio           12       Canada
Project         10       USA
Visi         


        
5条回答
  •  遥遥无期
    2021-01-13 14:56

    OK...Here's how to do it using PIVOT:

    SELECT Softwarename, Canada, USA, Canada + USA As TOTAL from SoftwareDemo 
    PIVOT 
        (
         SUM([Count])
         FOR Country
         IN (Canada, USA)
        ) AS x
    
    
    Softwarename                                       Canada      USA         TOTAL
    -------------------------------------------------- ----------- ----------- -----------
    Project                                            15          10          25
    Visio                                              12          5           17
    
    (2 row(s) affected)
    

提交回复
热议问题