我有一张简单的桌子

==============================
| playerId | score1 | score2 |
|============================|
|        1 |      1 |      2 |
|        1 |      5 |      1 |
|        2 |      6 |      6 |
|        2 |      1 |      3 |
==============================


我想对字段score1和score2求和,找出哪个球员的得分更高,所以这就是我所在的位置

SELECT MAX(sum(score1) + sum(score2)) FROM player_scores GROUP BY playerId


但是我明白了


  1111-无效使用组功能

最佳答案

简单而有效。

SELECT playerId, SUM( score1 + score2 )
FROM `test`
GROUP BY playerId
ORDER BY 2 DESC
LIMIT 1

10-08 18:35