본문 바로가기
취준/코팅 테스트

[LeetCode] 626. Exchange Seats

by 소복소복뚜벅뚜벅 2024. 4. 5.

문제 

Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.

Return the result table ordered by id in ascending order.

 

문제풀이

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

 

오답이유 

CASE 문을 사용해서 활용하는 문제인지 파악하지 못함.. 왜 CASE 문을 사용하는 법을 자꾸 까먹는거닝....