Spylot Spylot - 3 months ago 9
MySQL Question

2 columns. Merge duplicate values of A, sum duplicate values of B

I have a table that has 2 columns with data like this (from 1950 to 2015):

| Year | Count |
| 1994 | 10 |
| 1994 | 49 |
| 1994 | 2 |
| 1995 | 13 |
| 1995 | 6 |


I want my query result to be:

| Year | Count |
| 1994 | 61 |
| 1995 | 19 |


Things I have tried:

I began with a simple query like
SELECT SUM(Count) FROM 'population' WHERE 'Year' = '1994'
which was fine to bring a specific year but I wanted to fill an array with the population of every year in the database.

Doing something like
SELECT Year, SUM(Count) FROM 'population'
is closer to what I want except it just shown the first year only.

I'm not sure what terms I need to search up to get close to my answer. Union? I tried applying it but I just blerghed.

Answer

Try to use

SELECT year,SUM(Count) FROM 'population' group by year
Comments