如果总数为偶数直接替换相邻的同学,如果是奇数最大的id同学位置不变。用sql表达为
select * from
(
select b.id-1 id,b.student student FROM
seat a,seat b
where a.id+1=b.id
and mod(b.id,2) = 0
UNION
select a.id+1 id,a.student student FROM
seat a,seat b
where a.id+1=b.id
and mod(b.id,2) = 0
UNION
select a.id id,a.student student FROM
seat a
where mod(a.id,2) = 1
and a.id=(select max(id) from seat)
)c
order by id