[LeetCode] 626. Exchange Seats

2022. 6. 9. 23:38SQL

 

SELECT new_id AS id
      ,student
FROM (SELECT CASE WHEN MOD(id,2)=1 AND id=(SELECT MAX(id) FROM seat) THEN id
                WHEN MOD(id,2)=1 THEN (id+1)
                WHEN MOD(id,2)=0 THEN (id-1) 
             END AS new_id,
             student FROM seat) AS sub
ORDER BY new_id;