The Immediate Food Delivery II interview question is a more advanced version of the previous problem. Instead of looking at all orders, you only care about the first order placed by each customer. You need to find the percentage of these first orders that were "immediate" (order date matches preferred delivery date).
Companies like Apple and Amazon use this "Medium" SQL problem to test your knowledge of Subqueries and Grouping. It requires you to first identify a subset of the data (the first order for every user) and then perform a calculation on that subset. This is a common pattern in "Cohort Analysis" and "User Retention" metrics where only the initial interaction is analyzed.
The problem follows the Filtering by Minimum Value pattern.
customer_id and find the MIN(order_date) for each.IN clause) to select only the rows corresponding to those first orders.(customer_id, order_date) IN (...) query is much cleaner.Master the "First Row per Group" pattern. You can solve it using GROUP BY with MIN(), or using window functions like RANK() OVER(PARTITION BY customer_id ORDER BY order_date). In an interview, mention both to show breadth of knowledge.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Confirmation Rate | Medium | Solve | |
| Customers Who Bought All Products | Medium | Solve | |
| Product Sales Analysis III | Medium | Solve | |
| Rank Scores | Medium | Solve | |
| Product Price at a Given Date | Medium | Solve |