Stripe wants to know how quickly customers recover after a failed payment. For every failed payment that is later followed by a successful payment from the same customer, find the first successful payment that happened after it and compute the whole minutes between the two. Failed payments with no later success are ignored. If a customer has several failed payments before one success, each failed payment gets its own row paired with that same success. Write an SQL query that returns customer_id, failed_payment_id, recovered_payment_id and minutes_to_recover. Order the results by customer_id, then failed_payment_id.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.