Stromgren Stromgren - 1 year ago 59
MySQL Question

SQL: Selecting sum of two columns across multiple rows

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 |
-------------------------

Answer Source

Try using SUM()

SELECT Country,
 SUM(`Count 1` + `Count 2`) AS count
FROM table_name 
GROUP BY country
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download