Skip to content

Files

Latest commit

e1e4783 · Nov 23, 2018

History

History

ExchangeSeats

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 23, 2018
Nov 23, 2018

Exchange Seats

We can solve problem this problem by CASE function, or use union to solve it like below:

# Write your MySQL query statement below
select id, student from (
    select id - 1 as id, student from seat where mod(id, 2) = 0 union
    select id + 1 as id, student from seat where mod(id, 2) = 1 and id != (select count(*) from seat) union
    select id, student from seat where mod(id, 2) = 1 and id = (select count(*) from seat)
) as s order by id