Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Engaged Users by Region

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

Your question is Top Engaged 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

Asana Spa wants to identify its most engaged users across regional teams. Write a PostgreSQL query that finds the top three users in each region based on activity during the last 30 days.

Assume CURRENT_DATE is 2026-08-29 when validating the sample data.

Requirements

  1. Join users to their activity events and restrict events to the last 30 days.
  2. Count activity events for each user.
  3. Rank users independently within each region, showing at most three users per region.
  4. Return ties deterministically by sorting activity count descending and user ID ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User's display name
regionVARCHAR(50)User's regional team
activity_events
ColumnTypeDescription
event_idPKINTUnique activity event identifier
user_idINTUser associated with the event
event_timestampTIMESTAMPTime when the activity occurred
event_typeVARCHAR(50)Type of Asana activity
Tablesusersactivity_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results