Loading problem...
You are given a delivery log table named delivery.
Each row represents one placed order:
An order is called immediate when customer_pref_delivery_date equals order_date. Otherwise, it is scheduled.
For each customer, the first order is the row with that customer's earliest order_date. It is guaranteed that every customer has exactly one first order.
Compute the percentage of customers whose first order is immediate. Return one row with one column:
Round the percentage to 2 decimal places.
This problem supports both:
delivery:
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
|-------------|-------------|-------------|-----------------------------|
| 1 | 1 | 2019-08-01 | 2019-08-02 |
| 2 | 2 | 2019-08-02 | 2019-08-02 |
| 3 | 1 | 2019-08-11 | 2019-08-12 |
| 4 | 3 | 2019-08-24 | 2019-08-24 |
| 5 | 3 | 2019-08-21 | 2019-08-22 |
| 6 | 2 | 2019-08-11 | 2019-08-13 |
| 7 | 4 | 2019-08-09 | 2019-08-09 |[
{"immediate_percentage": 50.0}
]First orders are delivery_id 1, 2, 5, and 7. Customers 2 and 4 are immediate on first order, so percentage = 2/4 * 100 = 50.00.
delivery:
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
|-------------|-------------|-------------|-----------------------------|
| 10 | 100 | 2024-01-01 | 2024-01-01 |
| 11 | 101 | 2024-01-03 | 2024-01-06 |
| 12 | 102 | 2024-01-05 | 2024-01-05 |[
{"immediate_percentage": 66.67}
]Two of three customers are immediate on first order, so percentage = 66.67.
delivery:
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
|-------------|-------------|-------------|-----------------------------|
| 21 | 8 | 2023-03-01 | 2023-03-05 |
| 22 | 8 | 2023-03-04 | 2023-03-04 |
| 23 | 9 | 2023-06-10 | 2023-06-12 |[
{"immediate_percentage": 0.0}
]Customer 8 has a later immediate order, but the first order is scheduled. Customer 9 is also scheduled on first order.
Constraints