2 solutions - change student column / id column


  • 0
    Y
              select a.id, (case 
                    when a.id%2 =0 
                    then ( select b.student from seat b where a.id=b.id+1)
    
                    when a.id%2 <>0 and a.id<(select max(id)from seat)
                    then ( select b.student from seat b where a.id=b.id-1 ) 
               else a.student 
               end 
               ) student from seat a    
              
    
    
    
               select (case 
                      when id%2 = 0 then id-1 
                      when id%2<>0 and id< (select max(id) from seat) then id+1
               else id
               end
               )id , student from seat order by id

Log in to reply
 

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