MEDIUMVerified Real Interview• Analytics Engineer

Top 5 Streaming Artists by Hours Listened

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_name
  • artist_rank

Order by artist_rank ascending, then artist_name ascending.

Tables:

  • artists (artist_id INT, artist_name VARCHAR)
  • songs (song_id INT, artist_id INT)
  • global_streams (stream_id INT, song_id INT, duration_seconds INT, stream_date DATE)

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
⌘↵ Run Query
Ready to execute. Press Run (⌘+Enter)
Write your query and click “Run” or press ⌘+Enter to inspect output.