Your question is SQL Window Functions and Rolling Avg. Start with the requirements and the three 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.
ABC Family wants to monitor daily viewing trends in its streaming app. Write a PostgreSQL query that calculates a three-calendar-day rolling average of completed viewing minutes for each active ABC Family show.
US.| Column | Type | Description |
|---|---|---|
| show_idPK | INT | Unique show identifier |
| show_title | VARCHAR(100) | Show title |
| network | VARCHAR(50) | Network or platform owner |
| genre | VARCHAR(50) | Show genre |
| is_active | BOOLEAN | Whether the show is currently active |
| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| country | VARCHAR(2) | Two-letter user country code |
| Column | Type | Description |
|---|---|---|
| session_idPK | INT | Unique viewing session identifier |
| user_id | INT | User who watched the show |
| show_id | INT | Show being watched |
| started_at | DATE | Calendar date when viewing started |
| duration_minutes | INT | Minutes watched in the session |
| session_status | VARCHAR(20) | Session completion status |