Skip to content

1867. Orders With Maximum Quantity Above Average 👎

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
WITH
  GroupedOrders AS (
    SELECT
      order_id,
      MAX(quantity) AS max_quantity,
      MAX(AVG(quantity)) OVER() AS max_avg_quantity
    FROM OrdersDetails
    GROUP BY 1
  )
SELECT order_id
FROM GroupedOrders
WHERE max_quantity > max_avg_quantity;