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