Reputation: 1074
I have a table structure like this:
-------------------------------------
| Country | Count 1 | Count 2 |
-------------------------------------
| USA | 10 | 10 |
-------------------------------------
| USA | 10 | 10 |
-------------------------------------
| France | 200 | 200 |
-------------------------------------
| USA | 10 | 10 |
-------------------------------------
| France | 100 | 100 |
-------------------------------------
I would like to select the total of Count 1 and Count 2 for each country. So my output would be like
-------------------------
| Country | Count |
-------------------------
| USA | 60 |
-------------------------
| France | 600 |
-------------------------
Upvotes: 0
Views: 3759
Reputation: 153
Try this.
UPDATE power
SET cnt = SUM(IFNULL(is_yellow, 0) +
IFNULL(is_green, 0) + IFNULL(is_blue, 0));
Upvotes: 0
Reputation: 247710
This is pretty straight-forward, you can use the aggregate function SUM()
with a GROUP BY
:
SELECT country,
sum(count1 + count2) as Total
FROM yourtable
GROUP BY country;
See Demo
Upvotes: 2
Reputation: 3137
Try this
SELECT Country, SUM(Count_1 + Count_2)
FROM Table
GROUP BY Country
Upvotes: 1