Skip to content

Commit 5a3e60f

Browse files
ROW_NUMBER()
1 parent 91a82fc commit 5a3e60f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
WITH CumulativeWeight AS (
2+
SELECT
3+
person_name,
4+
turn,
5+
SUM(weight) OVER (ORDER BY turn ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS total_weight
6+
FROM Queue
7+
)
8+
SELECT person_name
9+
FROM CumulativeWeight
10+
WHERE total_weight <= 1000
11+
ORDER BY turn DESC
12+
LIMIT 1;

0 commit comments

Comments
 (0)