Recovering failed payments
MediumStripefirst attempt vs later attemptscumulative recoverydecline codestime to recoverypercentile_cont· 60 XP (20 per question)
Mock interview. You're interviewing for a data scientist job at a payments company. When a subscription payment fails, we retry it automatically: up to 3 more times, after 1, 3 and 5 more days. The interviewer says: "Failed payments are a big cause of subscribers leaving without meaning to. How well do retries work?"
invoices: one row per subscription payment due in September 2026.invoice_attempts: one row per attempt to collect it (attempt_no1 to 4), whether itsucceeded, and thedecline_codeif not.
Question 1: How many fail first time?
"Show invoices, the share that failed on the first attempt, and the mix of decline codes for those first failures."
Expected output
- Columns
decline_code,failed_invoices,pct_of_failures(rounded to 1 decimal),pct_of_all_invoices(rounded to 1 decimal); first attempts that failed only; sorted byfailed_invoices, highest first
Example of the shape (made-up values):
| decline_code | failed_invoices | pct_of_failures | pct_of_all_invoices |
|---|---|---|---|
| lost_card | 20 | 10.0 | 1.0 |
Hints, the later questions and the answer come with Pro.
Question 1 of 3
Write your query here. Ctrl + Enter submits.