use union


  • 0
    F

    373 ms

    select t.id, t.student from (
    select s1.id as id, s2.student from seat as s1 inner join seat as s2 on s1.id % 2 = 1 and s2.id % 2 = 0 and s1.id = s2.id - 1
    UNION
    select s1.id as id, s2.student from seat as s1 inner join seat as s2 on s1.id % 2 = 0 and s2.id % 2 = 1 and s1.id = s2.id + 1
    UNION
    select id, student from seat where id = (select max(id) from seat)
    order by id) as t group by t.id;


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.