Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Active Users Per Region
00:00
5 left

Top Active Users Per Region

MediumSQL · PostgreSQL

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
Interviewer

Your question is Top Active Users Per Region. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.