Your question is 7-Day Rolling DAU on Facebook. Start with the requirements and the one table on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Facebook wants to monitor short-term engagement trends by tracking the 7-day rolling average of daily active users (DAU). Write a SQL query to calculate this metric from app activity logs.
activity_date, daily_active_users, and rolling_7d_avg_dau.activity_date ascending.| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique event identifier |
| user_id | INT | Facebook user who generated the event |
| event_time | TIMESTAMP | Timestamp when the activity occurred |
| event_name | VARCHAR(50) | Type of user activity event |
| device_type | VARCHAR(20) | Device used for the event |