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
ExperiencesCoaching
New
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
Get started
SQL: DAU/MAU Ratio
00:00
5 left

SQL: DAU/MAU Ratio

MediumSQL · PostgreSQL

Problem

Meta's Product Growth team uses the AARRR funnel to monitor activation and retention across Instagram Reels, Facebook Groups, and Instagram Save activity. Write a PostgreSQL query that calculates the daily DAU/MAU ratio for the fixed 30-day period from 2025-03-01 through 2025-03-30.

Requirements

  1. Count distinct active users with at least one valid activity event per calendar day as dau.
  2. Count distinct active users with activity during the trailing 30-day period ending on each calendar day as mau.
  3. Return every calendar date in the reporting window, including dates with zero DAU.
  4. Calculate dau_mau_ratio as DAU divided by MAU, rounded to four decimal places. Avoid division by zero.

Output details

  • Return columns in this order: activity_date, dau, mau, dau_mau_ratio.
  • Order rows by activity_date ascending.
  • Count activity only for users whose account_status is active.
  • Restrict activity events to dates from 2025-03-01 through 2025-03-30 when calculating trailing 30-day metrics.
  • Treat each trailing window as inclusive of its calendar date and the preceding 29 dates.
  • Return NULL for dau_mau_ratio when mau is zero.

Schema

users
ColumnTypeDescription
user_idPKVARCHAR(20)Meta user identifier
account_statusVARCHAR(20)Current account state
signup_dateDATEAccount creation date
app_activity_events
ColumnTypeDescription
event_idPKINTUnique activity event identifier
user_idVARCHAR(20)User associated with the event
event_dateDATECalendar date of the event
surfaceVARCHAR(30)Meta product surface
event_nameVARCHAR(30)Recorded activity type
Tablesusersapp_activity_events
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.