Skip to content

Commit bea84c5

Browse files
authored
Update 35-01204-last-person-to-fit-in-the-bus.sql
1 parent 56a7f59 commit bea84c5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
-- use running total
2+
-- create a temp table which has running total of weights
3+
-- in the main query, pull the weight <= 1000, order by desc and limit 1
14

5+
select person_name
6+
from
7+
(
8+
select *, sum(weight) over(order by turn) as total_weight
9+
from Queue
10+
) temp
11+
where total_weight <= 1000
12+
order by turn desc
13+
limit 1
14+
15+
16+
-- amazon- 2
17+
-- wayfair- 2

0 commit comments

Comments
 (0)