MEDIUMVerified Real Interview• Analytics Engineer
Top 5 Streaming Artists by Hours Listened
Verified Source:Spotify Engineering Blog & Candidate Debrief
Spotify wants to recognize the top 5 artists with the highest total listening time across all users in February 2026.
Write a query to determine the top 5 artists ranked by total streaming hours. If multiple artists have the exact same total streaming hours, they should receive the same rank (dense rank). Output:
artist_nameartist_rank
Order by artist_rank ascending, then artist_name ascending.
Tables:
artists(artist_idINT,artist_nameVARCHAR)songs(song_idINT,artist_idINT)global_streams(stream_idINT,song_idINT,duration_secondsINT,stream_dateDATE)
Execution Sandbox:
Your query executes inside an isolated in-memory PostgreSQL engine (PGlite WebAssembly). You have full access to standard PostgreSQL aggregations, window functions, and CTEs.
Standard SQL (ANSI)|Ln 1, Col 1(7 lines, 121 chars)
Tab Indent⌘↵ Run Query
Ready to execute. Press Run (⌘+Enter)
Write your query and click “Run” or press ⌘+Enter to inspect output.