티스토리 뷰

https://leetcode.com/problems/exchange-seats

 

Exchange Seats - LeetCode

Can you solve this real interview question? Exchange Seats - Table: Seat +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | student | varchar | +-------------+---------+ id is the primary key (unique value) column for

leetcode.com

select
    case when id = (select max(id) from Seat) and id%2 > 0 then id
         when id%2 = 0 then id - 1
         when id%2 > 0 then id + 1
         end as id
    , student
from Seat
order by 1

'프로그래밍연습 > SQL' 카테고리의 다른 글

[SQL]rising-temperature  (0) 2023.08.24
[SQL]confirmation-rate  (0) 2023.08.22
[SQL]friend-requests-ii-who-has-the-most-friends  (0) 2023.08.20
[SQL]game-play-analysis-iv  (0) 2023.08.19
[SQL]human-traffic-of-stadium  (0) 2023.08.18
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함