Premium problem47. DAU to WAU Ratio

Medium Locked

events(user_id, event_at)

For every date from 2026-09-01 to 2026-09-07, return daily active users, weekly active users, and DAU as a percentage of WAU.

WAU is the number of distinct users active on that date or any of the six calendar dates before it, so the first few rows reach back into August.

Return date, dau, wau and dau_wau_pct rounded to two decimals, ordered by date. Every one of the seven dates appears even if nothing happened on it; when WAU is zero the percentage is NULL.

Grouping the events table alone cannot produce a row for a date with no events, so the dates have to be generated.

Tables

events

user_id  event_at
-------  -------------------
1        2026-08-27 10:00:00
2        2026-08-30 10:00:00
1        2026-09-01 10:00:00
3        2026-09-01 11:00:00
3        2026-09-02 10:00:00
4        2026-09-03 10:00:00
1        2026-09-05 10:00:00
5        2026-09-06 10:00:00
... 2 more row(s)

Expected result

date        dau  wau  dau_wau_pct
----------  ---  ---  -----------
2026-09-01  2    3    66.67
2026-09-02  1    3    33.33
2026-09-03  1    4    25.00
2026-09-04  0    4    0.00
2026-09-05  1    4    25.00
2026-09-06  1    4    25.00
2026-09-07  2    5    40.00

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query