LeetCode.626. 换座位
思路:
检索每一个id值,如果为奇数则设为i+1,如果是偶数则设为i-1,注意末位是奇是偶,重新输出即可。

代码:

select if(id<(select count(*) from seat),if(id%2=0,id-1,id+1),if(id%2=0,id-1,id)) as id,student
from seat
order by id;

相关文章:

  • 2022-02-28
  • 2021-07-10
  • 2021-06-22
  • 2021-11-15
  • 2021-11-06
  • 2021-07-09
  • 2021-08-15
  • 2021-09-30
猜你喜欢
  • 2022-12-23
  • 2021-06-06
  • 2022-02-11
  • 2022-12-23
  • 2021-12-14
  • 2022-02-09
  • 2021-11-17
相关资源
相似解决方案