求和两次并分组

sum two times and group

我有 table 这样的:

| ID | Team   | User    | Try1 | Try2 |  Try3 |
| 1  | Black  | Chris   |  2   |  6   |  4    |
| 2  | Black  | Brian   |  10  |  8   |  10   |
| 3  | Red    | Mark    |  6   |  2   |  8    |
| 4  | Red    | Andrew  |  4   |  10  |  6    |

我需要一起计算团队尝试点数以获得总分。

SELECT *, SUM(Try1 + Try2 + Try3) AS total FROM team_pts GROUP BY team ORDER BY total DESC

问题是 - 如何输出每个团队每次尝试的总数? 像这样:

| Pos | Team  | Try1 | Try2 | Try3 | Total |
|  1  | Black |  12  |  14  |  14  |  40   |
|  2  | Red   |  10  |  12  |  14  |  36   |

对不起我的英语!

SELECT ID,Team,SUM(Try1) as Try1,SUM(Try2) as Try2,SUM(Try3) as Try3,SUM(Try1 + Try2 + Try3) AS Total FROM team_pts GROUP BY 团队 ORDER BY 总 DESC

您需要在总和之前对列求和:

SELECT *,
       SUM(Try1),
       SUM(Try2),
       SUM(Try3),
       SUM(Try1 + Try2 + Try3) AS total
FROM team_pts
GROUP BY team
ORDER BY total DESC