simple case solution


  • 3
    H
    SELECT (CASE 
        WHEN mod(id, 2) != 0 and records != id THEN id + 1
        WHEN mod(id, 2) != 0 and records = id THEN id
        ELSE id - 1
    END) AS id, student
    FROM seat, (select count(*) as records from seat) as seat_records
    ORDER BY id asc;
    
    

  • 1

    @huahuahao2 said in simple case solution:

    SELECT (CASE
    WHEN mod(id, 2) != 0 and records != id THEN id + 1
    WHEN mod(id, 2) != 0 and records = id THEN id
    ELSE id - 1
    END) AS id, student
    FROM seat, (select count(*) as records from seat) as seat_records
    ORDER BY id asc;

    Best solution!


Log in to reply
 

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