Reputation: 1437
I have these data from a table. Example, I have table for points named tbl_points. tbl_points contains :
ptsID, team1, team2.
1 10 20
2 20 10
3 30 5
How do I create a query that will sum up the points for team1 and team2?
Upvotes: 0
Views: 107
Reputation: 40512
The following query:
SELECT
SUM(team1) AS team1_points,
SUM(team2) AS team2_points
FROM
tbl_points
will give you an one-row table as result:
| team1_points | team2_points |
| 60 | 35 |
Also, using name tbl_points
is not good. It's better to use no prefixes. Just name your table points
, it will be clear enough.
Upvotes: 1
Reputation: 219884
Untested:
SELECT SUM(p1.team1) AS team1_score
, SUM(p2.team2) AS team2_score
FROM tbl_points AS p1
, tbl_points AS p2
Upvotes: 1