Find January Shoppers Who Placed No Orders in February
Last updated: November 29, 2026
Quick Overview
Using an orders table (order_id, customer_id, order_date, status), list customers who placed at least one non-cancelled order in January 2026 and no non-cancelled order in February 2026.
Amazon
November 29, 20260
0
0 solved
Using an orders table (order_id, customer_id, order_date, status), list customers who placed at least one non-cancelled order in January 2026 and no non-cancelled order in February 2026.
Retail retention questions like this show up in Amazon online assessments for data scientist and BI-style roles. The grader is checking that you can write a correct anti-join, apply the same business filter (excluding cancellations) on both sides, and use half-open date ranges.
What the Interviewer Expects
- Write a correct anti-join using NOT EXISTS or LEFT JOIN ... IS NULL
- Apply the cancelled-order filter consistently on both the January and February side
- Use half-open date ranges so timestamps late on the last day are included
- Return distinct customers, not one row per January order
- Avoid NOT IN pitfalls with NULL customer_id values
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 turn this into a monthly lapse rate for every month in 2026?
- What if you also need customers who came back in March?
- How would you write this with LEFT JOIN and which version would you expect to run faster?
- How does the answer change if order_date is a timestamp in UTC but the business month is in local time?
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, order_date, status); one row per order.- "Placed an order" means a non-cancelled order. A customer whose only February order was cancelled still counts as lapsed, an...
Approach
This is an anti-join: start from January shoppers and remove anyone with a qualifying February order. I use NOT EXISTS because it is null-safe (a NOT IN against a subquery containing a NULL custom...