Career Hub/Interview questions/Premium Artist Diversity
Spotify logo

Premium Artist Diversity

Spotify·medium·SQL

Find highly engaged Premium subscribers. Return the user_id of every active Premium subscriber who has listened to at least 10 different artists in the current month. An active subscriber is one whose last login was within the past 30 days. Order by user_id.

Schema

users
user_idINTEGER
subscription_typeVARCHAR
last_loginDATE
subscription_type values: 'premium', 'free'
listening_history
listen_idINTEGER
user_idINTEGER
artist_idINTEGER
listened_atTIMESTAMP

Target output

Target output
user_id
1

What this question tests

Tests layered filtering: a subscription state, an activity recency window and a COUNT(DISTINCT) threshold in one query. Each condition is easy alone; the point is keeping row-level conditions in WHERE and the aggregate threshold in HAVING without mixing the two.

More SQL interview questions

  • 7-Day Rolling Listen Average · Spotify · medium
  • Highly Rated Listings · Airbnb · easy
  • Platform Split · Netflix · medium
Queryusers, listening_history
Cmd+Enterto runLoading...
Output

Loading sample data...