Find the bugs: DAU for the last three days
The report runs on February 3, 2026. To make the results reproducible, the query uses a fixed report date instead of CURRENT_DATE. Calculate DAU for the last three days, including the report date: February 1 through February 3. Return one row per day with the number of unique users who generated events. Mark the incorrect lines.
Find the errorsDatesMiddleAnalystData Engineer
Input data · iv_events
| id | user_id | event_type | created_at |
|---|---|---|---|
| 1 | 1 | login | 2026-01-31 23:59:00 |
| 2 | 1 | login | 2026-01-31 23:59:00 |
| 3 | 1 | view | 2026-02-01 00:00:00 |
| 4 | 2 | login | 2026-02-01 08:00:00 |
| 5 | 2 | view | 2026-02-01 08:05:00 |
| 6 | 2 | view | 2026-02-01 08:05:00 |
| 7 | 3 | login | 2026-02-02 10:00:00 |
| 8 | NULL | view | 2026-02-03 11:00:00 |
| 9 | 1 | purchase | 2026-02-03 12:00:00 |
| 10 | 2 | logout | 2026-02-28 23:59:59 |
SELECT CAST(created_at AS DATE) AS day,
COUNT(DISTINCT user_id) AS dau
FROM iv_events
WHERE created_at >= CAST('2026-02-03' AS DATE) - INTERVAL '3' DAY
AND created_at < CAST('2026-02-03' AS DATE) + INTERVAL '1' DAY
GROUP BY created_at
ORDER BY day