Exchange Seats

4pts
Seat Geek

Problem Statement

SeatGeek manages venue seating where students are seated in numerical order by their id. To mix things up, the venue wants to swap the seats of every two consecutive students.

Write an SQL query to swap the seat id for every two consecutive students. If the number of students is odd, the id of the last student is not swapped.

Rules:

  • Return the result table with columns id and student.
  • Results must be sorted by id in ascending order.
Tests your understanding of
Basic SQL, Conditional Logic, Math and CASE Statement

Input Tables

seat
id(INTEGER)student(VARCHAR)
1Abbot
2Doris
3Emerson
4Green
5Jeames

Expected Output

id(INTEGER)student(VARCHAR)
1Doris
2Abbot
3Green
4Emerson
5Jeames

Tags

MediumBasic SQLConditional LogicMathCASE Statement
15-20 min
68%

Hints