Skip to content

Commit 574fe8b

Browse files
committed
Update 626. Exchange Seats.sql
1 parent bcc48be commit 574fe8b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

LeetCode SQL 50 Solution/626. Exchange Seats.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,15 @@ Output:
5151
+----+---------+
5252
Explanation:
5353
Note that if the number of students is odd, there is no need to change the last one's seat.
54+
'''
5455

56+
# MYSQL Query Accepted
5557

58+
SELECT ( CASE
59+
WHEN id%2 != 0 AND id != counts THEN id+1
60+
WHEN id%2 != 0 AND id = counts THEN id
61+
ELSE id-1
62+
END) AS id, student
63+
FROM seat, (select count(*) as counts from seat)
64+
AS seat_counts
65+
ORDER BY id ASC

0 commit comments

Comments
 (0)