g0601_0700.s0626_exchange_seats.script.sql Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
# Write your MySQL query statement below
# #Medium #Database
select
id,
case when id % 2 = 1 and lead(student) over (order by id) is null then student
when id % 2 = 1 then lead(student) over (order by id)
else lag(student) over (order by id)
end as student
from seat
order by id asc