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