Skip to content

Commit a7ca12e

Browse files
committed
[LeetCode Sync] Runtime - 335 ms (60.42%), Memory - 0.0B (100.00%)
1 parent e8d627d commit a7ca12e

File tree

2 files changed

+52
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)