문제
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 문을 사용하는 법을 자꾸 까먹는거닝....
'취준 > 코팅 테스트' 카테고리의 다른 글
[LeetCode] - 1204. Last Person to Fit in the Bus (0) | 2024.04.06 |
---|---|
[LeetCode] 1484. Group Sold Products By The Date (0) | 2024.04.06 |
[LeetCode] - 601. Human Traffic Of Stadium (0) | 2024.04.05 |
[LeetCode] - 1661. Average Time Of Process per Machine (0) | 2024.04.04 |
[LeetCode] - 1321. Restaurant Growth (0) | 2024.04.03 |