我有这些来自表格的数据。例如,我有一个名为 tbl_points 的点表。tbl_points 包含:
ptsID, team1, team2.
1 10 20
2 20 10
3 30 5
如何创建一个查询来总结 team1 和 team2 的积分?
未经测试:
SELECT SUM(p1.team1) AS team1_score
, SUM(p2.team2) AS team2_score
FROM tbl_points AS p1
, tbl_points AS p2
以下查询:
SELECT
SUM(team1) AS team1_points,
SUM(team2) AS team2_points
FROM
tbl_points
结果会给你一个单行表:
| team1_points | team2_points |
| 60 | 35 |
此外,使用名称tbl_points
也不好。最好不使用前缀。只需为您的表命名points
,就足够清楚了。