Use COALESCE and CASE WHEN (SQL Server Accept)


  • 0
    G

    Use COALESCE and CASE WHEN (essentially same as if else but you can use that in SQL server)

    select coalesce(
    CASE WHEN s1.id % 2 = 0 THEN s1.id - 1 ELSE NULL END,
    CASE WHEN s1.id = (select max(s2.id) from seat s2) THEN s1.id ELSE s1.id + 1 END)as id,
        s1.student
    from seat s1
    Order by id
    

Log in to reply
 

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