Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top Users by Region

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

Your question is SQL Top Users by Region. Start with the requirements and the three 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. Write a PostgreSQL query that calculates engagement scores from recent Acumen activity and returns the top three ranks per region, preserving ties.

Use 2026-08-29 12:00:00+00 as the report timestamp so the result is reproducible. The reporting window includes events from the preceding 30 days, including the timestamp boundary.

Requirements

  1. Join users to engagement events and event types to calculate each user's score.
  2. Assign points from event_types.points and treat users with no scored activity as having a score of zero.
  3. Rank users independently within each region using a tie-aware window function.
  4. Return every user whose rank is at most 3, including all users tied at the third rank.
  5. Order results by region, rank, and user ID.

Representative data

user_iduser_nameregion
1Ava ChenNorth
2Ben OrtizNorth
3Cara SinghNorth
5Emi ParkSouth
9Iris ColeWest
12Liam ReedEast
event_iduser_idevent_type_idoccurred_at
101132026-08-28 09:00:00+00
103252026-08-01 14:00:00+00
104342026-08-02 10:00:00+00
107552026-08-15 08:00:00+00
112952026-08-27 16:00:00+00
115452026-07-01 12:00:00+00

Schema

users
ColumnTypeDescription
user_idPKINTUnique Acumen user identifier
user_nameVARCHAR(100)User display name
regionVARCHAR(50)User's geographic region
engagement_events
ColumnTypeDescription
event_idPKINTUnique engagement event identifier
user_idINTUser who generated the event
event_type_idINTType of engagement event
occurred_atTIMESTAMPTZTimestamp when the event occurred
event_types
ColumnTypeDescription
event_type_idPKINTUnique event type identifier
event_nameVARCHAR(50)Human-readable event name
pointsINTEngagement points awarded for the event
Tablesusersengagement_eventsevent_types
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results