Days from First to Second Order for New Customers
Last updated: November 29, 2026
Quick Overview
For each monthly cohort of new customers, compute the share who placed a second delivered order within 30 days of their first, plus the median days to the second order among those who returned.
DoorDash
November 29, 20260
0
0 solved
For each monthly cohort of new customers, compute the share who placed a second delivered order within 30 days of their first, plus the median days to the second order among those who returned.
Second-order rate is one of the clearest early retention signals for a DoorDash consumer, and growth teams use it to judge new-user promos. The interviewer is checking basic window function fluency and whether you handle censoring for customers whose 30-day window has not closed.
What the Interviewer Expects
- Use ROW_NUMBER to find the first and second order per customer
- Pivot rn = 1 and rn = 2 into columns with conditional aggregation
- Exclude cohorts whose 30-day window is still open
- Be clear that the median is over returners only
- Count only delivered orders, not cancelled ones
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 split this by whether the first order used a new-customer promo?
- How would you produce a full curve of cumulative repeat rate by day 1 through 60?
- Why might the median days to second order look better for a cohort that actually retained worse?
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
Assume orders(order_id, customer_id, created_at, status). A customer's first order is their earliest delivered order. A repeat within 30 days means a second delivered order at most 30 days after the...
Approach
Rank delivered orders per customer, keep ranks 1 and 2, and pivot them into first_at and second_at with MAX(CASE ...). Group customers by the month of first_at. A customer with no second order...