SQL interview question: Monthly User Retention Rate
Calculate Monthly Retention Rate
Product managers need to understand how many users from each month return the following month.
Calculate month-over-month retention rate. A user is "retained" if they were active in both the current month AND the previous month.
Return month (YYYY-MM format) and retention_rate, rounded to 2 decimal places. Only include months that have a previous month of activity. Formula: (Retained Users / Previous Month Users) × 100
Inspired by Meta's data science interview questions
Tables
user_events 13 rows
- event_id integer PK
- user_id integer
- event_time text
- event_type text
| event_id | user_id | event_time | event_type |
|---|---|---|---|
| 1 | 1 | 2025-01-05 10:00:00 | page_view |
| 2 | 1 | 2025-01-05 10:05:00 | click |
| 3 | 1 | 2025-01-05 10:15:00 | page_view |