题目来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/exchange-seats
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
本人思考:
– 1、当id为奇数时id+1,为偶数时id-1
– 2、注意当id为奇数时需要判断id是否为最后一个id ,即等于id的个数
select
case
when mod(id,2) !=0 and id != (select count(id) from seat) then id+1
when mod(id,2) !=0 and id = (select count(id) from seat) then id
else id-1
end as id,
student
from seat
order by id