Skip to content

Commit bcc48be

Browse files
committed
Update 626. Exchange Seats.sql
1 parent fef6387 commit bcc48be

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
626. Exchange Seats
2+
Solved
3+
Medium
4+
Topics
5+
Companies
6+
SQL Schema
7+
Pandas Schema
8+
Table: Seat
9+
10+
+-------------+---------+
11+
| Column Name | Type |
12+
+-------------+---------+
13+
| id | int |
14+
| student | varchar |
15+
+-------------+---------+
16+
id is the primary key (unique value) column for this table.
17+
Each row of this table indicates the name and the ID of a student.
18+
The ID sequence always starts from 1 and increments continuously.
19+
20+
21+
Write a solution 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.
22+
23+
Return the result table ordered by id in ascending order.
24+
25+
The result format is in the following example.
26+
27+
28+
29+
Example 1:
30+
31+
Input:
32+
Seat table:
33+
+----+---------+
34+
| id | student |
35+
+----+---------+
36+
| 1 | Abbot |
37+
| 2 | Doris |
38+
| 3 | Emerson |
39+
| 4 | Green |
40+
| 5 | Jeames |
41+
+----+---------+
42+
Output:
43+
+----+---------+
44+
| id | student |
45+
+----+---------+
46+
| 1 | Doris |
47+
| 2 | Abbot |
48+
| 3 | Green |
49+
| 4 | Emerson |
50+
| 5 | Jeames |
51+
+----+---------+
52+
Explanation:
53+
Note that if the number of students is odd, there is no need to change the last one's seat.
54+
55+

0 commit comments

Comments
 (0)