Skip to content

Commit 7abd5a2

Browse files
authored
Create orders-with-maximum-quantity-above-average.sql
1 parent 3169dd8 commit 7abd5a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
WITH cte AS
5+
(SELECT order_id,
6+
AVG(quantity) AS avg_quantity,
7+
MAX(quantity) AS max_quantity
8+
FROM OrdersDetails
9+
GROUP BY order_id
10+
ORDER BY NULL)
11+
12+
SELECT order_id
13+
FROM cte
14+
WHERE max_quantity >
15+
(SELECT MAX(avg_quantity) AS max_avg_quantity
16+
FROM cte);

0 commit comments

Comments
 (0)