Flag Merchants Whose Rolling Seven Day Dispute Rate Spikes
Last updated: November 29, 2026
Quick Overview
Write SQL over charges and disputes that computes, for every merchant and calendar day, the trailing 7 day dispute rate and a 28 day baseline ending a week earlier, and flags merchant-days where the recent rate is at least 1%, at least three times the baseline, and backed by at least five disputes.
Stripe
November 29, 20260
0
0 solved
Write SQL over charges and disputes that computes, for every merchant and calendar day, the trailing 7 day dispute rate and a 28 day baseline ending a week earlier, and flags merchant-days where the recent rate is at least 1%, at least three times the baseline, and backed by at least five disputes.
Card networks fine merchants whose dispute ratios cross thresholds, and Stripe's risk and Radar teams watch for sudden spikes that signal fraud attacks or broken fulfillment. This SQL question checks time series fundamentals: building a dense calendar spine so ROWS windows mean days, separating the recent window from the baseline, and adding volume floors so tiny merchants do not trigger noise.
What the Interviewer Expects
- Builds a per-merchant daily calendar spine so days with no activity still count
- Uses ROWS windows on the dense spine (or RANGE with intervals) and explains the difference
- Keeps the baseline window disjoint from the recent window
- Applies minimum count thresholds and requires a full baseline
- Explains the numerator and denominator timing mismatch between disputes and charges
- Uses NULLIF to avoid divide by zero
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Disputes arrive weeks after the charge. Would you attribute them to the dispute date or the charge date, and why?
- How would you rewrite this to run incrementally each day instead of over all history?
- A merchant with 30 charges a week gets 2 disputes. How would a Bayesian or Poisson approach handle it better than fixed thresholds?
- How would you suppress repeat alerts for the same merchant on consecutive days?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
charges(charge_id, merchant_id, created_at) and disputes(dispute_id, charge_id, created_at). I use dispute activity: disputes opened in the window over charges created in the window. It is not a c...
Approach
- Spine: generate every day from a merchant's first charge to yesterday. Without it,
ROWS BETWEEN 6 PRECEDINGon sparse data spans more than 7 calendar days. - Daily facts: charge and disp...