1204.sql (156B)
1 SELECT Q1.person_name 2 FROM Queue Q1 3 JOIN Queue Q2 4 ON Q1.turn >= Q2.turn 5 GROUP BY Q1.turn 6 HAVING SUM(Q2.weight) <= 1000 7 ORDER BY SUM(Q2.weight) DESC 8 LIMIT 1