Find double-billing risk: pairs of subscriptions of the SAME tenant whose periods overlap. Periods are inclusive of both start_date and end_date; end_date NULL means still active and is treated as '2026-12-31' (the reporting date). Return tenant_id, sub_id_1 (smaller id), sub_id_2 (larger id) and overlap_days (number of calendar days covered by both, inclusive). Order by tenant_id, sub_id_1, sub_id_2.
| Column | Type |
|---|---|
| sub_id | INTEGER |
| tenant_id | TEXT |
| plan | TEXT |
| start_date | DATE |
| end_date | DATE |
| sub_id | tenant_id | plan | start_date | end_date |
|---|---|---|---|---|
| 1 | T1 | E3 | 2026-01-01 | 2026-03-31 |
| 2 | T1 | E5 | 2026-03-15 | 2026-06-30 |
| 3 | T1 | Teams Essentials | 2026-07-01 | NULL |
| 4 | T2 | E3 | 2026-02-01 | 2026-02-28 |
| 5 | T2 | E3 | 2026-03-01 | 2026-03-31 |
| 6 | T3 | Business Basic | 2026-01-10 | NULL |
| 7 | T3 | Business Premium | 2026-05-01 | 2026-05-20 |
| tenant_id | sub_id_1 | sub_id_2 | overlap_days |
|---|---|---|---|
| T1 | 1 | 2 | 17 |
| T3 | 6 | 7 | 20 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Current Account Owner From SCD Type 2 · First-Touch vs Last-Touch Attribution ›
{{ 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.