Skip to Main Content

MySQL Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Looking for a MYSQL mentor. I'm new to this language and would appreciate having someone to ask questions directly.

Ademitan FajemirokunJun 3 2024 — edited Jun 3 2024

delivery_id is the column of unique values of this table. The table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).

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.

This was my query but its wrong:

Could I get some help? Thank you very much.

WITH CTE AS
(SELECT DISTINCT customer_id, sum(if(datediff(customer_pref_delivery_date, order_date) = 0, 1, 0)) as immediate
FROM Delivery
GROUP BY customer_id)
SELECT ROUND(100*sum(immediate) / sum(customer_id), 2) as immediate_percentage FROM CTE
Comments
Post Details
Added on Jun 3 2024
0 comments
216 views