Your question is Window Functions for Engagement. Start with the requirements and the two tables 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.
AARP.org wants to monitor engagement trends for active users. Write a PostgreSQL query that aggregates engagement by user and day, then calculates both cumulative engagement and a three-day moving average.
account_status is active.engagement_date for January 1 through January 5, 2025. Treat a day containing only NULL minutes as zero.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique user identifier |
| display_name | VARCHAR(100) | User's display name |
| account_status | VARCHAR(20) | Current account status |
| Column | Type | Description |
|---|---|---|
| event_idPK | INTEGER | Unique engagement event identifier |
| user_id | INTEGER | References users.user_id |
| engagement_date | DATE | Date of the engagement event |
| engagement_minutes | INTEGER | Minutes attributed to the event |