Only orders with status 'DELIVERED' count as revenue (ignore RETURNED and CANCELLED everywhere, including when deciding a customer's cohort). A customer's cohort is the calendar month of their first delivered order; month offset 0 is that month, 1 is the next calendar month, and so on. For each cohort return cohort_month ('YYYY-MM'), cohort_size (customers), and ltv_m0, ltv_m1, ltv_m2 = cumulative delivered revenue of the cohort up to and including month offset 0/1/2, divided by cohort_size, ROUND to 2. Order by cohort_month.
| Column | Type |
|---|---|
| order_id | INTEGER |
| customer_id | INTEGER |
| order_date | DATE |
| amount | REAL |
| status | TEXT |
| order_id | customer_id | order_date | amount | status |
|---|---|---|---|---|
| 1 | 1 | 2026-01-05 | 1000 | DELIVERED |
| 2 | 1 | 2026-02-10 | 500 | DELIVERED |
| 3 | 2 | 2026-01-20 | 800 | DELIVERED |
| 4 | 2 | 2026-03-02 | 400 | DELIVERED |
| 5 | 3 | 2026-02-03 | 1200 | DELIVERED |
| 6 | 3 | 2026-02-25 | 300 | RETURNED |
| 7 | 3 | 2026-03-15 | 600 | DELIVERED |
| 8 | 4 | 2026-02-14 | 700 | DELIVERED |
| cohort_month | cohort_size | ltv_m0 | ltv_m1 | ltv_m2 |
|---|---|---|---|---|
| 2026-01 | 2 | 900 | 1150 | 1350 |
| 2026-02 | 2 | 950 | 1250 | 1250 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Wallet Balance With Compliance Resets · Longest Daily Login Streak ›
{{ 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.