Swap adjacent seat ids
MediumP3Coding
Table seat:
| Column | Type |
|---|---|
| id | int (primary key, 1, 2, 3, ... with no gaps) |
| student | text |
Swap the students of every two adjacent seats: seat 1 with seat 2, seat 3 with seat 4, and so on. If the number of seats is odd, the last student keeps their seat. Ids stay in place, only names move.
Output columns: id, student. Order by id.
Schema
CREATE TABLE seat ( id int PRIMARY KEY, student text NOT NULL );
Example 1
- Input
- seat: (1, A), (2, B), (3, C), (4, D)
- Output
- (1, B), (2, A), (3, D), (4, C)
Example 2
- Input
- seat: (1, A), (2, B), (3, C)
- Output
- (1, B), (2, A), (3, C)
Constraints
- PostgreSQL dialect.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
PostgreSQL
Run checks the 3 visible tests, Submit all 6. ⌘Enter runs, ⌘⇧Enter submits.