Write SQL and Python, run instantly in your browser, and track your progress.
You are a Data Scientist at Netflix. To better understand user engagement, you are conducting a study on the viewing habits of active users over the last six months. Your focus is on successfully completed viewing sessions.
Your task is to create a clean dataset for this analysis by joining playback_sessions with users. The dataset must only include sessions from active users that were completed, had a positive watch duration, and occurred within the last 180 days.
The final output should include the session and user IDs, the user's country (in uppercase), the total watch time converted to whole minutes, and the session's start date.
| Column Name | Type |
|---|
You are a Data Scientist at Netflix. To better understand user engagement, you are conducting a study on the viewing habits of active users over the last six months. Your focus is on successfully completed viewing sessions.
Your task is to create a clean dataset for this analysis by joining playback_sessions with users. The dataset must only include sessions from active users that were completed, had a positive watch duration, and occurred within the last 180 days.
The final output should include the session and user IDs, the user's country (in uppercase), the total watch time converted to whole minutes, and the session's start date.
| Column Name | Type |
|---|
| session_id | INTEGER |
| user_id | INTEGER |
| device_id | INTEGER |
| title_id | INTEGER |
| episode_id | INTEGER |
| started_at | TEXT |
| ended_at | TEXT |
| watch_seconds | INTEGER |
| quality | TEXT |
| session_id | INTEGER |
| user_id | INTEGER |
| device_id | INTEGER |
| title_id | INTEGER |
| episode_id | INTEGER |
| started_at | TEXT |
| ended_at | TEXT |
| watch_seconds | INTEGER |
| quality | TEXT |
| session_id | user_id | device_id | title_id | episode_id | started_at | ended_at | watch_seconds | quality | status |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 2 | 205 |
| session_id | user_id | device_id | title_id | episode_id | started_at | ended_at | watch_seconds | quality | status |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 2 | 205 |
| Column Name | Type |
|---|---|
| user_id | INTEGER |
| TEXT | |
| full_name | TEXT |
| country | TEXT |
| language | TEXT |
| created_at | TEXT |
| Column Name | Type |
|---|---|
| user_id | INTEGER |
| TEXT | |
| full_name | TEXT |
| country | TEXT |
| language | TEXT |
| created_at | TEXT |
| user_id | full_name | country | language | created_at | account_status | |
|---|---|---|---|---|---|---|
| 1 | andrewbrown@icloud.com | Andrew Brown | CA | en | 2025-06-14 | active |
| 2 |
| user_id | full_name | country | language | created_at | account_status | |
|---|---|---|---|---|---|---|
| 1 | andrewbrown@icloud.com | Andrew Brown | CA | en | 2025-06-14 | active |
| 2 |
| session_id | user_id | country_upper | watch_minutes | start_date |
|---|---|---|---|---|
| 10 | 2 | US | 28 | 2025-08-30 |
| 337 | 40 | GB | 50 | 2025-08-30 |
| 487 | 59 | FR | 33 | 2025-08-30 |
| session_id | user_id | country_upper | watch_minutes | start_date |
|---|---|---|---|---|
| 10 | 2 | US | 28 | 2025-08-30 |
| 337 | 40 | GB | 50 | 2025-08-30 |
| 487 | 59 | FR | 33 | 2025-08-30 |
Showing first 5 of 201 rows. Completed playback sessions from active users sorted by start date descending.
Showing first 5 of 201 rows. Completed playback sessions from active users sorted by start date descending.
Your final output should be a result set that meets the following requirements:
1. Joining & Filtering:
playback_sessions and users tables must be joined on user_id.playback_sessions.status is 'completed'.ended_at is not NULL.watch_seconds is greater than 0.Your final output should be a result set that meets the following requirements:
1. Joining & Filtering:
playback_sessions and users tables must be joined on user_id.playback_sessions.status is 'completed'.ended_at is not NULL.watch_seconds is greater than 0.| status |
| status |
| TEXT |
| TEXT |
| 2025-06-26T05:44:01 |
| 2025-06-26T05:44:01 |
| 2025-06-26T06:33:55 |
| 2025-06-26T06:33:55 |
| 2700 |
| 2700 |
| hd |
| hd |
| completed |
| completed |
| 2 | 1 | 1 | 139 | 2025-04-04T23:41:32 | 2025-04-04T23:57:22 | 678 | 4k | abandoned |
| 2 | 1 | 1 | 139 | 2025-04-04T23:41:32 | 2025-04-04T23:57:22 | 678 | 4k | abandoned |
| 3 | 1 | 2 | 328 | 2024-12-04T15:21:55 | 2024-12-04T16:07:01 | 2460 | 4k | completed |
| 3 | 1 | 2 | 328 | 2024-12-04T15:21:55 | 2024-12-04T16:07:01 | 2460 | 4k | completed |
| 4 | 1 | 1 | 38 | 2025-02-15T10:35:42 | 2025-02-15T11:40:58 | 3626 | uhd | abandoned |
| 4 | 1 | 1 | 38 | 2025-02-15T10:35:42 | 2025-02-15T11:40:58 | 3626 | uhd | abandoned |
| 5 | 1 | 1 | 5 | 2025-06-15T03:24:01 | 2025-06-15T03:33:03 | 293 | sd | error |
| 5 | 1 | 1 | 5 | 2025-06-15T03:24:01 | 2025-06-15T03:33:03 | 293 | sd | error |
| account_status | TEXT |
| account_status | TEXT |
| anthony.dubois@mail.com |
| anthony.dubois@mail.com |
| Anthony Dubois |
| Anthony Dubois |
| US |
| US |
| en |
| en |
| 2024-11-24 |
| 2024-11-24 |
| active |
| active |
| 3 | david92@hotmail.com | David Wagner | ES | es | 2024-11-25 | active |
| 3 | david92@hotmail.com | David Wagner | ES | es | 2024-11-25 | active |
| 4 | valentina_smith@outlook.com | Valentina Smith | DE | de | 2024-12-17 | active |
| 4 | valentina_smith@outlook.com | Valentina Smith | DE | de | 2024-12-17 | active |
| 5 | omar.wilson@yahoo.com | Omar Wilson | FR | fr | 2025-07-27 | active |
| 5 | omar.wilson@yahoo.com | Omar Wilson | FR | fr | 2025-07-27 | active |
| 409 | 49 | IN | 27 | 2025-08-29 |
| 409 | 49 | IN | 27 | 2025-08-29 |
| 104 | 12 | IN | 37 | 2025-08-27 |
| 104 | 12 | IN | 37 | 2025-08-27 |
users.account_statususers.account_statusstarted_at time is within the last 180 days.started_at time is within the last 180 days.2. Transformations:
2. Transformations:
users.country column must be converted to uppercase and aliased as country_upper.watch_minutes column must be created by converting watch_seconds to the nearest whole minute. For example, 89 seconds should be 1 minute, and 91 seconds should be 2 minutes.started_at timestamp must be formatted as a date ('YYYY-MM-DD') and aliased as start_date.users.country column must be converted to uppercase and aliased as country_upper.watch_minutes column must be created by converting watch_seconds to the nearest whole minute. For example, 89 seconds should be 1 minute, and 91 seconds should be 2 minutes.started_at timestamp must be formatted as a date ('YYYY-MM-DD') and aliased as start_date.3. Columns:
3. Columns:
session_iduser_idcountry_upperwatch_minutesstart_datesession_iduser_idcountry_upperwatch_minutesstart_date4. Ordering:
4. Ordering:
start_date in descending order (newest first).session_id in ascending order.start_date in descending order (newest first).session_id in ascending order.