将条件看做三种情况,分别处理
SELECT
CASE
WHEN id % 2=1 and id=(select COUNT(*) from Seat) THEN id
WHEN id % 2=0 THEN id-1
Else id+1
END AS id,student
FROM Seat
ORDER BY id;
别人的解法
select rank() over (order by (id - 1) ^ 1) id, student
from Seat
# 这也太厉害了吧!!!
# (id-1)^1 可以实现奇数不变,偶数-2的效果;^1可实现奇数+1,偶数-1
# rank() over 重新排序,从1开始,最后把序号给id
标签:语句,over,rank,Seat,---,sql,id,select
From: https://www.cnblogs.com/Zhouya/p/17415976.html