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

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

    You can pivot your data 'manually':

    SELECT SUM(CASE WHEN name='bob' THEN points END) as bob,
           SUM(CASE WHEN name='mike' THEN points END) as mike
      FROM score_table
    

    but this will not work if the list of your players is dynamic.

提交回复
热议问题