mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
update
This commit is contained in:
50
leetcode/problem/exchange-seats.html
Normal file
50
leetcode/problem/exchange-seats.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<p>Table: <code>Seat</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+---------+
|
||||
| Column Name | Type |
|
||||
+-------------+---------+
|
||||
| id | int |
|
||||
| name | varchar |
|
||||
+-------------+---------+
|
||||
id is the primary key column for this table.
|
||||
Each row of this table indicates the name and the ID of a student.
|
||||
id is a continuous increment.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write an SQL query to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.</p>
|
||||
|
||||
<p>Return the result table ordered by <code>id</code> <strong>in ascending order</strong>.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Seat table:
|
||||
+----+---------+
|
||||
| id | student |
|
||||
+----+---------+
|
||||
| 1 | Abbot |
|
||||
| 2 | Doris |
|
||||
| 3 | Emerson |
|
||||
| 4 | Green |
|
||||
| 5 | Jeames |
|
||||
+----+---------+
|
||||
<strong>Output:</strong>
|
||||
+----+---------+
|
||||
| id | student |
|
||||
+----+---------+
|
||||
| 1 | Doris |
|
||||
| 2 | Abbot |
|
||||
| 3 | Green |
|
||||
| 4 | Emerson |
|
||||
| 5 | Jeames |
|
||||
+----+---------+
|
||||
<strong>Explanation:</strong>
|
||||
Note that if the number of students is odd, there is no need to change the last one's seat.
|
||||
</pre>
|
Reference in New Issue
Block a user