Skip to content

Commit 9a3f400

Browse files
committedApr 25, 2020
refactor 626
1 parent 041bef3 commit 9a3f400

File tree

1 file changed

+0
-30
lines changed

1 file changed

+0
-30
lines changed
 

‎database/_626.sql

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
--626. Exchange Seats
2-
--
3-
--Mary is a teacher in a middle school and she has a table seat storing students' names and their corresponding seat ids.
4-
--
5-
--The column id is continuous increment.
6-
--Mary wants to change seats for the adjacent students.
7-
--Can you write a SQL query to output the result for Mary?
8-
--+---------+---------+
9-
--| id | student |
10-
--+---------+---------+
11-
--| 1 | Abbot |
12-
--| 2 | Doris |
13-
--| 3 | Emerson |
14-
--| 4 | Green |
15-
--| 5 | Jeames |
16-
--+---------+---------+
17-
--For the sample input, the output is:
18-
--+---------+---------+
19-
--| id | student |
20-
--+---------+---------+
21-
--| 1 | Doris |
22-
--| 2 | Abbot |
23-
--| 3 | Green |
24-
--| 4 | Emerson |
25-
--| 5 | Jeames |
26-
--+---------+---------+
27-
--Note:
28-
--If the number of students is odd, there is no need to change the last one's seat.
29-
30-
311
SELECT
322
(CASE
333
WHEN MOD(id, 2) != 0 AND counts != id THEN id + 1

0 commit comments

Comments
 (0)
Please sign in to comment.