Skip to content

Commit 51cfc2f

Browse files
Update 1204. Last Person to Fit in the Bus.sql
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com>
1 parent a304fd1 commit 51cfc2f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

LeetCode SQL 50 Solution/1204. Last Person to Fit in the Bus.sql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,19 @@ Explanation: The folowing table is ordered by the turn for simplicity.
5757
| 4 | 2 | Marie | 200 | 1200 | (cannot board)
5858
| 5 | 4 | Bob | 175 | ___ |
5959
| 6 | 1 | Winston | 500 | ___ |
60-
+------+----+-----------+--------+--------------+
60+
+------+----+-----------+--------+--------------+
61+
62+
63+
64+
# Write your MySQL query statement below
65+
SELECT a.person_name
66+
FROM
67+
Queue AS a,
68+
Queue AS b
69+
WHERE a.turn >= b.turn
70+
GROUP BY a.person_id
71+
HAVING SUM(b.weight) <= 1000
72+
ORDER BY a.turn DESC
73+
LIMIT 1;
74+
75+

0 commit comments

Comments
 (0)