Monthly Repeat Customer Rate by City From Orders
Last updated: November 29, 2026
Quick Overview
Using an orders table with order id, customer id, city, created timestamp and status, compute for each city and calendar month the number of ordering customers, the number with two or more delivered orders that month, and the repeat rate.
Swiggy
November 29, 20260
0
0 solved
Using an orders table with order id, customer id, city, created timestamp and status, compute for each city and calendar month the number of ordering customers, the number with two or more delivered orders that month, and the repeat rate.
Order frequency is one of the main health metrics for Swiggy food delivery and for Swiggy One, and analysts slice it by city constantly. An online assessment uses this to check clean aggregation, correct status filtering and avoiding integer division.
What the Interviewer Expects
- Filters to delivered orders before counting
- Aggregates per customer first, then per city and month
- Uses a month key derived from the timestamp
- Avoids integer division when computing the rate
- States how customers who ordered in two cities are treated
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 compute a rolling 30-day repeat rate instead of calendar months?
- How do you attribute a customer who orders in Bengaluru and Pune in the same month?
- How would you exclude orders that were delivered but fully refunded?
- How would you show whether new Swiggy One members drive the change in repeat rate?
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
orders(order_id, customer_id, city, created_at, status). Status values include delivered and cancelled. I assume city is the delivery city of that order, timestamps are in IST, and a repeat cust...
Approach
Two-level aggregation. First collapse to one row per (city, month, customer) with the delivered order count. Then per (city, month) count customers and sum a CASE flag for counts of two or more. Multi...