Compute Daily Active Users and DAU Over MAU Stickiness in SQL

Last updated: November 29, 2026

Quick Overview

Using an events table (project_id, distinct_id, event_name, event_time), write SQL that returns, for each day in the last 30 days, daily active users, trailing 28-day active users, and their ratio.

Mixpanel
Data Manipulation (SQL/Python)
Data Scientist
Mixpanel
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Using an events table (project_id, distinct_id, event_name, event_time), write SQL that returns, for each day in the last 30 days, daily active users, trailing 28-day active users, and their ratio.

Stickiness (DAU/MAU) is a metric Mixpanel customers chart constantly and that Mixpanel's own growth team watches for its product. The screen checks that you count distinct users correctly over a rolling window rather than summing daily counts.

What the Interviewer Expects
  • Count distinct users per day, not events
  • Compute the rolling window with a date-range join, not a sum of daily DAUs
  • Define which events count as active
  • Handle timezone of the day boundary
  • Guard against division by zero
Key Topics to Cover
distinct counts
rolling windows
date spine
stickiness
SQL joins
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 cheap enough to run on billions of rows every hour?
  • Why can DAU/MAU rise while both DAU and MAU fall?
  • How would you show stickiness for only users who signed up in the last 90 days?
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

One row per event. 'Active' means any event except passive ones like $session_start or push received, which I would exclude explicitly. Days are bucketed in the project's timezone; I will assume UTC...

Approach
  1. Reduce events to one row per (user, day), which shrinks data massively.
  2. DAU is a count of those rows per day.
  3. For the rolling window, join each report day to user-days within the previous 27 ...

Submit Your Answer
Markdown supported

Related Questions