Leetcode Problem 2686. Immediate Food Delivery III

2686. Immediate Food Delivery III

Leetcode Solutions

Calculating Immediate Order Percentage with Conditional Aggregation

  1. Select the order_date from the Delivery table.
  2. Use the AVG() function with a condition that checks if order_date equals customer_pref_delivery_date. This condition will return 1 for immediate orders and 0 for scheduled orders.
  3. Multiply the average by 100 to get the percentage.
  4. Use the ROUND() function to round the result to two decimal places.
  5. Group the results by order_date.
  6. Order the final result by order_date in ascending order.

erDiagram
    Delivery {
        int delivery_id PK "Unique delivery identifier"
        int customer_id "Identifier of the customer"
        date order_date "Date when the order was placed"
        date customer_pref_delivery_date "Preferred delivery date by the customer"
    }

Using Conditional SUM and COUNT to Calculate Immediate Order Percentage

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...