Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Active Users Per Region

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

Your question is Top Active Users Per 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

Alteryx wants to identify the most engaged users across account regions. Using activity recorded in its user event pipeline, write a PostgreSQL query that finds the top three active users in each region over the 30-day period ending on 2025-02-15.

Requirements

  1. Join users to account details and user events.
  2. Include only events from 2025-01-17 through 2025-02-15, inclusive. Ignore events with a NULL timestamp and accounts without a region.
  3. Calculate each user's event count, number of active calendar days, and distinct event types.
  4. Rank users within each region by event count descending, active days descending, and user ID ascending as the deterministic tie-breaker.
  5. Return no more than three users per region, with the ranking included in the output.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User display name
account_idINTAccount associated with the user
account_details
ColumnTypeDescription
account_idPKINTUnique account identifier
regionVARCHAR(50)Geographic region assigned to the account
user_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser who generated the event
event_typeVARCHAR(50)Type of user activity
event_timestampTIMESTAMPTimestamp when the event occurred
Tablesusersaccount_detailsuser_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results