如何在mySQL中显示最高分

时间:2017-10-25 09:35:33

标签: mysql sum max

我想在几轮之后展示得分最高的球员。 这是表格:

PlayerID   Round   number of score
   1         1           4
   2         1           5
   3         1           8
   1         2           3
   2         2           10
   3         2           7

预期产出

PlayerID         number of score
   2                     15
   3                     15

我试过这段代码,但这里有错误。如何显示输出?

SELECT playerID , MAX(SUM(numberOfGoals)) FROM Game;

2 个答案:

答案 0 :(得分:2)

尝试:

SELECT playerID,  SUM(numberOfGoals) AS numberOfGoals
FROM Game
GROUP BY playerID
HAVING SUM(numberOfGoals) IN (SELECT MAX(goals) FROM (SELECT SUM(numberOfGoals) goals 
FROM Game GROUP BY playerID) t)

Results

答案 1 :(得分:1)

SELECT playerId, Sum(numberofscore)
FROM Game 
Group By PlayerId
Order By Sum(numberofscore) Desc