Write SQL and Python, run instantly in your browser, and track your progress.
You are a Data Analyst at Netflix. The Content team wants to analyze viewing trends by calculating a rolling average of watch time. Calculate a 3-session rolling average of watch_seconds for the playback sessions, ordered by session_id.
| Column Name | Type |
|---|---|
| session_id | int64 |
| user_id | int64 |
| watch_seconds | int64 |
| quality | object |
You are a Data Analyst at Netflix. The Content team wants to analyze viewing trends by calculating a rolling average of watch time. Calculate a 3-session rolling average of watch_seconds for the playback sessions, ordered by session_id.
| Column Name | Type |
|---|---|
| session_id | int64 |
| user_id | int64 |
| watch_seconds | int64 |
| quality | object |
| session_id | user_id | watch_seconds | quality |
|---|---|---|---|
| 1 | 101 | 1800 | hd |
| 2 | 102 | 3600 | 4k |
| 3 | 101 | 2400 |
| session_id | user_id | watch_seconds | quality |
|---|---|---|---|
| 1 | 101 | 1800 | hd |
| 2 | 102 | 3600 | 4k |
| 3 | 101 | 2400 |
| session_id | watch_seconds | rolling_avg |
|---|---|---|
| 1 | 2700 | NaN |
| 2 | 678 | NaN |
| 3 | 2460 | 1946 |
| 4 | 3626 | 2254.67 |
| 5 | 293 | 2126.33 |
| session_id | watch_seconds | rolling_avg |
|---|---|---|
| 1 | 2700 | NaN |
| 2 | 678 | NaN |
| 3 | 2460 | 1946 |
| 4 | 3626 | 2254.67 |
| 5 | 293 | 2126.33 |
Showing first 5 of 497 rows.
Showing first 5 of 497 rows.
1. Data Selection:
2. Window Function:
3. Output:
1. Data Selection:
2. Window Function:
3. Output:
| hd |
| hd |
| 4 | 103 | 1200 | sd |
| 4 | 103 | 1200 | sd |
| 5 | 102 | 4200 | 4k |
| 5 | 102 | 4200 | 4k |