Interview Questions/SQL/Immediate Food Delivery II

Immediate Food Delivery II

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Immediate Food Delivery II

You have a Delivery table. Each delivery has an order_date and a customer_pref_delivery_date. A delivery is considered 'immediate' if the order_date equals the customer_pref_delivery_date; otherwise it is 'scheduled'. Each customer's first order is the one with the minimum order_date. Write a SQL query to find the percentage of customers whose first order was immediate. Round to 2 decimal places.

Examples

Example 1

Customer 1's first order (id=1) is scheduled. Customer 2's first order (id=2) is immediate. Customer 3's first order (id=5) is scheduled. Customer 4's first order (id=7) is immediate. 2 out of 4 = 50.00%.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql