MySQL row into number of columns and sum

后端 未结 3 1901
深忆病人
深忆病人 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:34

    Try this:

    SELECT ID, Car_num
       , SUM(IF(Service = 'shower', Price, 0)) AS Shower
       , SUM(IF(Service = 'TV', Price, 0)) AS TV
    FROM your_table
    GROUP BY Car_num;
    

提交回复
热议问题