The join and filter parts were fine, excluding test users is just a WHERE clause.
Start by generating a complete date series for the last 30 days using a recursive CTE or a date dimension table to ensure all days are represented, even those with zero events. Then join to the app_events and users tables, filtering out test users and aggregating distinct user counts per day. Finally, compute the 7-day rolling average using a window function and order by date.
Pro tip: Explicitly state your assumptions about test user identification (e.g., email domain or a flag) and timezone handling (events stored in UTC). This shows attention to data quality and prevents ambiguity.
Create a list of all UTC calendar days for the last 30 days using a recursive CTE or a date dimension table. This ensures days with no events are included.
Join the date series to app_events and users, filter out test users, and count distinct non-test users with at least one event per day.
Use a window function to calculate the 7-day rolling average of DAU, ordering by date and including the current day and the six preceding days.
Select the date, DAU, and rolling average, ensuring the result is ordered by date ascending and limited to the last 30 days.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.