MySQL SUM related to parent query

MySQL

I'm trying to put together a query to aggregate some information into a view, and am having trouble working out how to get that data I need from a couple of different tables. I'll start by describing the 3 tables I'm working with.

I have artists, which is as follows:

Ref | Artist
  1 | Metallica

I have tracks:

Filename | Title             | artist_ref
     001 | Sad But True      |       1
     002 | Through The Never |       1

And lastly I have popularity:

Filename | week | month | quarter
     001 |   23 |    42 |     138
     002 |    4 |    23 |      42

What I'm trying to do is get an aggregated popularity table formatted as so:

artist_ref | week | month | quarter
         1 |   27 |    65 |     180

I understand I'll have to use some kind of subquery and SUM, but my knowledge of this area is fairly limited. Any help is hugely appreciated as I'm finding this a bit of a brain buster!

Best Answer

Select artist_ref, SUM(week) as week,
SUM(month) as month,SUM(quarter) as quarter
FROM tracks LEFT JOIN popularity
USING (Filename)
group by artist_ref;

SAMPLE FIDDLE