Your question is Rolling 7-Day Revenue in SQL. 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.
Publicis Sapient is analyzing daily revenue trends for an active-user reporting dashboard. Write a PostgreSQL query that calculates a rolling seven-day average of daily revenue for each active user from January 1 through January 7, 2024.
| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| is_active | BOOLEAN | Whether the user is active |
| Column | Type | Description |
|---|---|---|
| event_idPK | INTEGER | Unique revenue event identifier |
| user_id | INTEGER | User associated with the revenue event |
| event_date | DATE | Calendar date of the event |
| event_type | VARCHAR(30) | Revenue event category |
| amount | NUMERIC(12,2) | Revenue amount |