D8LooPFocus modeCODE WORKSPACE
Write a query that returns weekly retention by signup cohort for active users in the first eight weeks after signup.
Start by isolating the first valid signup week per user, then layer active weeks after deduplication.
Sample input
| user_id | signup_week | active_week | event_name |
|---|---|---|---|
| 1 | 1 | 1 | signup |
| 1 | 1 | 2 | session_start |
| 2 | 1 | 1 | signup |
| 3 | 2 | 2 | signup |
Expected output
| signup_week | active_week | retained_users |
|---|---|---|
| 1 | 1 | 2 |
| 1 | 2 | 1 |
| 2 | 2 | 1 |
Constraints
Assume duplicate events exist, users can reactivate, and the final answer must be readable enough for an interviewer to follow.
Expected skills
Window functions, cohort logic, deduplication, and communicating tradeoffs.
Run the SQL query to inspect preview rows.