Flag Sellers Whose Monthly Late Shipment Rate Exceeds Four Percent
Last updated: November 29, 2026
Quick Overview
Given a shipments table with promised and actual ship dates per seller, write a query that returns each seller and month where the late shipment rate exceeded 4%, considering only seller-months with at least 50 shipments.
Amazon
November 29, 20260
0
0 solved
Given a shipments table with promised and actual ship dates per seller, write a query that returns each seller and month where the late shipment rate exceeded 4%, considering only seller-months with at least 50 shipments.
Seller performance metrics such as late shipment rate drive account health actions on Amazon's marketplace, and SQL screens for Data Scientist and BI roles often start here. The interviewer checks conditional aggregation, HAVING versus WHERE, and careful handling of shipments not yet shipped.
What the Interviewer Expects
- Conditional aggregation with CASE inside SUM
- Correct month bucketing
- Filtering aggregates with HAVING
- Handling NULL actual ship dates
- Avoiding integer division
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 find sellers above the threshold for three consecutive months?
- How would you compute the rate in rolling 30 day windows instead of calendar months?
- Should canceled orders count?
- How would you compare each seller to their category's average?
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 shipments(shipment_id, seller_id, promised_ship_date DATE, actual_ship_date DATE NULL).
- A shipment is late if it shipped after its promised date, or if it has not shipped and the promise...
Approach
- Filter to shipments that are due (
promised_ship_date < CURRENT_DATE). - Bucket by
seller_idandDATE_TRUNC('month', promised_ship_date). - Count total and late using a CASE expression insid...