MySql Case and Select


  • 0
    V
    select q.id,
    case 
          when q.id%2 = 0 then (select e.student from seat e where e.id = q.id-1)
          when (select count(g.id) from seat g where g.id=q.id+1) > 0 then (select f.student 
          from seat f where f.id = q.id+1)
          else q.student
    end as 'student' from seat q order by q.id asc;
    

Log in to reply
 

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