2022-03-27 20:46:41 +08:00
|
|
|
|
<p>表: <code>Seat</code></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
+-------------+---------+
|
|
|
|
|
| Column Name | Type |
|
|
|
|
|
+-------------+---------+
|
|
|
|
|
| id | int |
|
2023-12-09 18:42:21 +08:00
|
|
|
|
| student | varchar |
|
2022-03-27 20:46:41 +08:00
|
|
|
|
+-------------+---------+
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<code>id</code> 是该表的主键(唯一值)列。
|
|
|
|
|
该表的每一行都表示学生的姓名和 ID。
|
|
|
|
|
id 是一个连续的增量。
|
2022-03-27 20:46:41 +08:00
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>编写解决方案来交换每两个连续的学生的座位号。如果学生的数量是奇数,则最后一个学生的id不交换。</p>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
|
|
|
|
|
<p>按 <code>id</code> <strong>升序</strong> 返回结果表。</p>
|
|
|
|
|
|
|
|
|
|
<p>查询结果格式如下所示。</p>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
<strong>输入:</strong>
|
|
|
|
|
Seat 表:
|
|
|
|
|
+----+---------+
|
|
|
|
|
| id | student |
|
|
|
|
|
+----+---------+
|
|
|
|
|
| 1 | Abbot |
|
|
|
|
|
| 2 | Doris |
|
|
|
|
|
| 3 | Emerson |
|
|
|
|
|
| 4 | Green |
|
|
|
|
|
| 5 | Jeames |
|
|
|
|
|
+----+---------+
|
|
|
|
|
<strong>输出:</strong>
|
|
|
|
|
+----+---------+
|
|
|
|
|
| id | student |
|
|
|
|
|
+----+---------+
|
|
|
|
|
| 1 | Doris |
|
|
|
|
|
| 2 | Abbot |
|
|
|
|
|
| 3 | Green |
|
|
|
|
|
| 4 | Emerson |
|
|
|
|
|
| 5 | Jeames |
|
|
|
|
|
+----+---------+
|
|
|
|
|
<strong>解释:
|
|
|
|
|
</strong>请注意,如果学生人数为奇数,则不需要更换最后一名学生的座位。</pre>
|