Leetcode Problem 1867. Orders With Maximum Quantity Above Average

1867. Orders With Maximum Quantity Above Average

Leetcode Solutions

Subquery to Find Imbalanced Orders

  • Start by selecting order_id, quantity, and using aggregate functions AVG(quantity) and MAX(quantity) grouped by order_id.
  • Use a subquery to calculate the maximum average quantity across all orders.
  • In the outer query, use the HAVING clause to compare the maximum quantity of each order with the maximum average quantity obtained from the subquery.
  • Select only the order_id of the orders that meet the imbalanced condition.

erDiagram
    OrdersDetails {
        int order_id
        int product_id
        int quantity
        order_id product_id PK
    }

Window Function to Find Imbalanced Orders

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...