Select multiple sums with MySQL query and display them in separate columns

后端 未结 6 1120
无人及你
无人及你 2021-01-02 03:38

Let\'s say I have a hypothetical table like so that records when some player in some game scores a point:

name   points
------------
bob     10
mike    03
mi         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 04:13

    This is called pivoting the table:

    SELECT SUM(IF(name = "Bob", points, 0)) AS points_bob,
           SUM(IF(name = "Mike", points, 0)) AS points_mike
    FROM score_table
    

提交回复
热议问题