member_activity has one row per user activity (user_id, activity_date); a user can have several rows on the same day. For every date that has activity, except the latest date in the table (its next day is not observed yet), compute the next-day retention: the percentage of distinct users active on that date who are also active on the following calendar day (0 if nobody returns). Output columns: activity_date, retention_pct (rounded to 2 decimals). Order by activity_date ascending.
| Column | Type |
|---|---|
| user_id | INTEGER |
| activity_date | DATE |
| user_id | activity_date |
|---|---|
| 1 | 2026-01-01 |
| 1 | 2026-01-02 |
| 2 | 2026-01-01 |
| 3 | 2026-01-01 |
| 3 | 2026-01-03 |
| 4 | 2026-01-02 |
| 4 | 2026-01-03 |
| activity_date | retention_pct |
|---|---|
| 2026-01-01 | 33.33 |
| 2026-01-02 | 50 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
{{ 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.