AnalystPath

Swap Adjacent Relay Lanes

SQLMediumMid level~15 min

Problem

Table: `lane`

| Column Name | Type |
|---|---|
| lane_no | int |
| runner | varchar |

`lane_no` is the primary key. The lane numbers always start at 1 and increase without gaps.

The coach wants to swap the `runner` in each pair of adjacent lanes: lanes 1 and 2 trade places, lanes 3 and 4 trade places, and so on. If the highest lane number is odd, that last runner keeps their lane. Return the result ordered by `lane_no` ascending, with columns `lane_no` and `runner`.

Tables

Example rows — the live problem includes the full dataset.

lane
lane_norunner
1Reyes
2Okafor
3Petrov

Expected output

Your answer should return 5 rows with the columns lane_no, runner.

Starter code (SQL)

SELECT *
FROM lane;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions