SQL interview question: Rows Above Their Group Average

Above-Average Track Length per Album

The music team wants to identify unusually long tracks on each album.

Find tracks that are longer than the average track length on their album.

Return album_title, track_title, duration (in seconds), and album_avg_duration. Use a correlated subquery or window function. Show the 10 longest (duration descending).

Skills: correlated subquery for row-wise comparison

Tables

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

Keep going