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

后端 未结 6 1150
无人及你
无人及你 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:26

    SELECT sum(points), name
    FROM `table`
    GROUP BY name
    

    Or for the pivot

    SELECT sum(if(name = 'mike',points,0)),
           sum(if(name = 'bob',points,0))
    FROM `table
    

提交回复
热议问题