Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling 30-Day Active Users SQL
00:00
5 left

Rolling 30-Day Active Users SQL

HardSQL · PostgreSQL

Problem

Publicis Groupe analysts are evaluating regional engagement across a digital audience platform. Write a PostgreSQL query that measures distinct active users during the trailing 30-day window ending on 2024-02-01, assigns each region an engagement tier, and ranks regions within their tier.

Requirements

  1. Join users to user_activity while retaining regions whose users had no qualifying activity.
  2. Count distinct users with activity from 2024-01-03 through 2024-02-01, inclusive.
  3. Assign tiers using High for at least 3 active users, Medium for 1 or 2, and Low for 0.
  4. Use a window function to rank regions within each tier by active-user count descending, with region name as a deterministic tie-breaker in the final output.
  5. Exclude users whose region is NULL.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
regionVARCHAR(50)Geographic region assigned to the user
user_activity
ColumnTypeDescription
activity_idPKINTUnique activity event identifier
user_idINTUser associated with the activity event
activity_dateDATECalendar date on which the activity occurred
Tablesusersuser_activity
Interviewer

Your question is Rolling 30-Day Active Users SQL. Start with the requirements and the two 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.