MySQL row into number of columns and sum

后端 未结 3 1903
深忆病人
深忆病人 2021-01-17 05:55

Could somebody help with my SQL?

I have a table with records such as:

ID | Car_num | Service | Price
---+---------+---------+------
1  | 001     | sh         


        
3条回答
  •  滥情空心
    2021-01-17 06:22

    SELECT ROW_NUMBER() OVER(ORDER BY Car_num) Id,Car_num ,ISNULL([TV],0) [TV],ISNULL([shower],0) [shower]
    

    FROM ( SELECT Car_num , _Service , ISNULL(Price,0) Price FROM #Table )Data PIVOT ( MAX(Price) FOR _Service IN ([TV],[shower]) )AS PVT

提交回复
热议问题