Amazon wants to know how many new Prime members come back the very next month. Group members into cohorts by the calendar month of `signup_date`. A member is *retained* if they placed at least one order in the calendar month immediately after their signup month (orders in the signup month itself, or two or more months later, do not count; several orders count once). Return `cohort_month` ('YYYY-MM'), `cohort_size`, `retained_m1`, `retention_pct` = ROUND(100.0 * retained_m1 / cohort_size, 1). Every cohort must appear, even if nobody was retained. Order by `cohort_month`.
| Column | Type |
|---|---|
| customer_id | INTEGER |
| signup_date | DATE |
| customer_id | signup_date |
|---|---|
| 1 | 2026-01-05 |
| 2 | 2026-01-20 |
| 3 | 2026-01-28 |
| 4 | 2026-02-02 |
| 5 | 2026-02-14 |
| 6 | 2026-03-03 |
| Column | Type |
|---|---|
| order_id | INTEGER |
| customer_id | INTEGER |
| order_date | DATE |
| order_id | customer_id | order_date |
|---|---|---|
| 101 | 1 | 2026-01-06 |
| 102 | 1 | 2026-02-10 |
| 103 | 2 | 2026-02-01 |
| 104 | 2 | 2026-02-15 |
| 105 | 3 | 2026-03-05 |
| 106 | 4 | 2026-03-01 |
| 107 | 5 | 2026-02-20 |
| 108 | 6 | 2026-04-30 |
| cohort_month | cohort_size | retained_m1 | retention_pct |
|---|---|---|---|
| 2026-01 | 3 | 2 | 66.7 |
| 2026-02 | 2 | 1 | 50 |
| 2026-03 | 1 | 1 | 100 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Infrastructure Active Hours · Top-3 Products per Category with Ties ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.