Your question is Top 5 Shows Last 7 Days. 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.
Netflix Customer Insights needs a ranked view of the titles watched most during the previous seven days. Write a PostgreSQL query using 2025-02-08 12:00:00 as the reference time so the result is reproducible.
Include streams that overlap the seven-day window from 2025-02-01 12:00:00 through the reference time. Calculate watch time in minutes, clip sessions to the window boundaries, treat a NULL end_time as still active at the reference time, and return the top five Netflix titles.
streams to shows to return the title.| Column | Type | Description |
|---|---|---|
| stream_idPK | INT | Unique stream session identifier |
| user_id | INT | Netflix member identifier |
| show_id | INT | Referenced title identifier |
| start_time | TIMESTAMP | Time at which the stream started |
| end_time | TIMESTAMP | Time at which the stream ended, null for an active session |
| Column | Type | Description |
|---|---|---|
| show_idPK | INT | Unique Netflix title identifier |
| title | VARCHAR(150) | Netflix show or series title |