Coding Test

Leetcode - 626. Exchange Seats

Indo Yoon

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

정답

SELECT 
CASE
    WHEN id = len AND id % 2 = 1 THEN id
    WHEN id % 2 = 1 THEN id + 1
    ELSE id - 1
END AS id, student
FROM Seat, (
    SELECT COUNT(*) AS len
    FROM Seat
) AS NewSeat
ORDER BY id