Medium JOINsAggregation Premium

SQL interview question: Counts and Totals Across Joined Tables

Most Prolific Artists

The editorial team wants to feature artists ranked by their catalog size.

For each artist, show their album count, total tracks, and total play time in minutes.

Return artist_name, album_count, track_count, and total_minutes (rounded to 1 decimal). Order by track_count descending.

Skills: multiple aggregates with GROUP BY across JOINs

Tables

artists 10 rows
  • artist_id integer PK
  • name text
  • genre text
artist_idnamegenre
1The BeatlesRock
2Pink FloydProgressive Rock
3Michael JacksonPop
albums 18 rows
  • album_id integer PK
  • title text
  • artist_id integer → artists
  • release_year integer
album_idtitleartist_idrelease_year
1Abbey Road11969
2Sgt. Pepper's Lonely Hearts Club Band11967
3The White Album11968
tracks 40 rows
  • track_id integer PK
  • title text
  • album_id integer → albums
  • duration_seconds integer
track_idtitlealbum_idduration_seconds
1Come Together1259
2Something1182
3Here Comes the Sun1185

Keep going