Your question is Retention Cohorts With Complex Joins. 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.
Twitch wants to measure how consistently viewers return after their first qualifying stream session. Write a PostgreSQL query that builds monthly viewer retention cohorts for activity during 2025.
| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique Twitch viewer identifier |
| display_name | VARCHAR(80) | Twitch display name |
| created_at | DATE | Date the viewer account was created |
| Column | Type | Description |
|---|---|---|
| session_idPK | INT | Unique watched-session identifier |
| user_id | INT | Viewer who watched the session |
| channel_id | INT | Twitch channel associated with the session |
| started_at | TIMESTAMP | Session start timestamp |
| Column | Type | Description |
|---|---|---|
| channel_idPK | INT | Unique Twitch channel identifier |
| channel_name | VARCHAR(100) | Twitch channel name |
| is_active | BOOLEAN | Whether the channel is eligible for retention analysis |