A risk team wants to catch accidental double-billing. Only charges with status 'succeeded' matter; ignore every other status completely. A succeeded charge is a REPEAT when the previous succeeded charge with the same card_id, merchant_id and amount happened at most 10 minutes (600 seconds, inclusive) earlier. If two charges share the same timestamp, the one with the smaller charge_id counts as earlier. Return merchant_id, repeat_charges (number of repeat charges) and repeat_amount (sum of their amounts, ROUND to 2) for merchants with at least one repeat. Order by repeat_charges DESC, then merchant_id ASC.
| Column | Type |
|---|---|
| charge_id | INTEGER |
| card_id | TEXT |
| merchant_id | TEXT |
| amount | REAL |
| status | TEXT |
| charged_at | TIMESTAMP |
| charge_id | card_id | merchant_id | amount | status | charged_at |
|---|---|---|---|---|---|
| 1 | card_A | m_books | 499 | succeeded | 2026-02-01 10:00:00 |
| 2 | card_A | m_books | 499 | succeeded | 2026-02-01 10:04:30 |
| 3 | card_A | m_books | 499 | succeeded | 2026-02-01 10:20:00 |
| 4 | card_B | m_books | 120 | succeeded | 2026-02-01 11:00:00 |
| 5 | card_B | m_books | 120 | failed | 2026-02-01 11:01:00 |
| 6 | card_B | m_books | 120 | succeeded | 2026-02-01 11:02:00 |
| 7 | card_C | m_cabs | 80 | succeeded | 2026-02-01 09:00:00 |
| 8 | card_C | m_cabs | 85 | succeeded | 2026-02-01 09:03:00 |
| merchant_id | repeat_charges | repeat_amount |
|---|---|---|
| m_books | 2 | 619 |
| m_cabs | 1 | 80 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Orders per Delivery Partner with Unassigned · Payment Success Funnel by Method ›
{{ 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.