Thirty Day Repeat Purchase Rate From The Same Supplier
Last updated: November 29, 2026
Quick Overview
Given an orders table (order_id, user_id, supplier_id, order_date, status), write SQL that computes, for each supplier, the share of first-time buyers who placed another non-cancelled order with the same supplier within 30 days of their first one.
Meesho
November 29, 20260
0
0 solved
Given an orders table (order_id, user_id, supplier_id, order_date, status), write SQL that computes, for each supplier, the share of first-time buyers who placed another non-cancelled order with the same supplier within 30 days of their first one.
On a marketplace of small unbranded suppliers, repeat purchase from the same supplier is a strong signal of product quality and seller trust, and Meesho uses supplier-level quality signals in ranking. The interviewer checks cohort definition, window logic on dates, and choices about cancellations and same-day orders.
What the Interviewer Expects
- Defines the first order per user and supplier after removing cancellations
- Bounds the window strictly after the first order and within 30 days
- Decides and states how same-day multiple orders are treated
- Aggregates to a per-supplier rate with counts alongside
- Notes right-censoring for recent first orders
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 first orders from the last 30 days so the rate is not biased down?
- Rewrite the EXISTS with window functions. Which is faster on a large table?
- Should a returned order count as a repeat? Why or why not?
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
One row per order; status includes CANCELLED, DELIVERED, RETURNED, RTO. I count any non-cancelled order as a purchase (I would confirm whether RTO should also be excluded, since the buyer re...
Approach
valid: non-cancelled orders with the date.firsts:MIN(order_date)per(user_id, supplier_id).- Flag each first-time pair if another valid order exists with a date strictly after the f...