So I have a table weather
that looks something like this:
country | occurences
USA | 5
UK | 1
BOL | 1
USA | 2
UK | 1
and this table weatherOccurences
is what I want to generate:
country | occurenceTotal
USA | 7
UK | 2
BOL | 1
Basically, for every distinct country I want to calculate all the occurences for it... but I'm not sure how to do that. I tried:
INSERT INTO weatherOccurences(`occurenceTotal`)
SELECT SUM(occurences) from weather w1
JOIN weatherOccurences w2
ON w1.country = w2.country
However, instead of giving me the occurence count of each country, it just took a sum of all the occurences ever... and appended it to a new row at the end. How would I do the former? Any help would be greatly appreciated, thanks!
[edit] would I have to use UPDATE
and SET
for this?