Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Users by Region

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Users by Region. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Acumen wants to identify its most engaged users in each region. As of February 15, 2025, write a PostgreSQL query to find the top three users per region based on engagement points earned during the previous 30 days.

Requirements

  1. Include engagement events from January 16 through February 15, 2025, inclusive.
  2. Sum each user's non-null score within the period.
  3. Rank users independently within each region using ROW_NUMBER(), ordering by total score descending and user_id ascending as the tie-breaker.
  4. Return only ranks 1 through 3, with regions ordered alphabetically and users ordered by rank.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique Acumen user identifier
user_nameVARCHAR(100)User display name
regionVARCHAR(50)User geographic region
engagement_events
ColumnTypeDescription
event_idPKINTEGERUnique engagement event identifier
user_idINTEGERReferences users.user_id
event_atTIMESTAMPTimestamp when the engagement occurred
event_typeVARCHAR(50)Type of engagement action
scoreNUMERIC(10,2)Points assigned to the event
Tablesusersengagement_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results