Rolling DAU over MAU Stickiness for Every Calendar Day

Last updated: November 29, 2026

Quick Overview

From a user activity log, write SQL that returns DAU, trailing 28-day MAU, and the DAU/MAU ratio for each calendar date, including days with no activity.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


From a user activity log, write SQL that returns DAU, trailing 28-day MAU, and the DAU/MAU ratio for each calendar date, including days with no activity.

Stickiness (DAU/MAU) is one of the most watched engagement ratios at Meta, and computing a rolling distinct count is a classic Hard SQL item because COUNT DISTINCT cannot be used inside a sliding window frame. Interviewers check the calendar join, correct window boundaries, and awareness of the cost at scale.

What the Interviewer Expects
  • Explains why COUNT DISTINCT over a window frame is not available
  • Builds a calendar so missing days still appear
  • Joins each date to the trailing 28-day range with correct inclusive bounds
  • Computes DAU and MAU in one pass
  • Discusses performance and approximate alternatives like HyperLogLog
Key Topics to Cover
Rolling distinct counts
Calendar tables
Range joins
Engagement metrics
Approximate counting
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you make this efficient for 3 billion users?
  • How would you compute WAU/MAU in the same query?
  • Why should the first 27 days of the series be excluded or flagged?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Table: user_activity(user_id, activity_ts) with many rows per user per day. MAU for date dd means distinct users active on any day in [d−27,d][d-27, d], 28 days including dd. DAU is distinct users on $d...

Approach

Window functions with COUNT(DISTINCT ...) over a frame are not supported in most engines, and a sum of daily DAUs over 28 days double counts. So:

  1. Reduce to one row per user per day.
  2. Generate a...

Submit Your Answer
Markdown supported