* Problem
If the customer's preferred delivery date is the same as the order date, then the order is called immediate; otherwise, it is called scheduled.
The first order of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.
Write a solution to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.
* Explanation
The customer id 1 has a first order with delivery id 1 and it is scheduled.
The customer id 2 has a first order with delivery id 2 and it is immediate.
The customer id 3 has a first order with delivery id 5 and it is scheduled.
The customer id 4 has a first order with delivery id 7 and it is immediate.
Hence, half the customers have immediate first orders.
*Solution
# Write your MySQL query statement below
select round(avg(order_date = customer_pref_delivery_date)*100, 2) as immediate_percentage
from Delivery
where (customer_id,order_date) in
(select customer_id, min(order_date)
from Delivery
group by customer_id)
'Study - Problems(IT) > LeetCode - SQL' 카테고리의 다른 글
2356.Number of Unique Subjects Taught by Each Teacher (0) | 2024.11.20 |
---|---|
550. Game Play Analysis IV (0) | 2024.11.19 |
1193.Monthly Transactions (0) | 2024.11.16 |
1211.Queries Quality and Percentage (0) | 2024.11.15 |
1633. Percentage of Users Attended a Contest (1) | 2024.11.14 |