Find Previously Active Sellers Who Stopped Taking Payments
Last updated: November 29, 2026
Quick Overview
Given a payments table, write SQL that returns sellers who completed payments on at least 5 distinct days in the 90 days before the most recent 30-day window, but have no completed payments in that 30-day window, ranked by their prior volume.
Square
November 29, 20260
0
0 solved
Given a payments table, write SQL that returns sellers who completed payments on at least 5 distinct days in the 90 days before the most recent 30-day window, but have no completed payments in that 30-day window, ranked by their prior volume.
Seller retention is a core metric for Square, and account managers and lifecycle marketing need a reliable list of sellers who have gone quiet. The interviewer checks careful date windows, filtering on payment status, an anti-join, and whether you question what 'churned' should mean for seasonal businesses.
What the Interviewer Expects
- Clarify status values and use only completed payments
- Define non-overlapping windows precisely relative to an as-of date
- Count distinct active days rather than payment rows
- Use a LEFT JOIN or NOT EXISTS anti-join
- Raise seasonality and timezone concerns
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
- How would you exclude sellers whose business is seasonal, like a summer farmers market stand?
- How would you compute this for every as-of date to build a churn time series?
- Which seller attributes would you join in to prioritize outreach?
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
Table payments(payment_id, merchant_id, created_at, amount_cents, status). Status includes COMPLETED, FAILED and CANCELED; only COMPLETED counts. Refunds live in another table and are ignored for ac...
Approach
Build two windows: prior is [as_of - 120 days, as_of - 30 days) and recent is [as_of - 30 days, as_of). Aggregate prior activity per seller with a HAVING on distinct days, collect sellers with any rec...