Skip to content

Commit 083d34e

Browse files
authored
feat: update sql solution to lc problem: No.0626 (#1869)
1 parent 4de9712 commit 083d34e

File tree

3 files changed

+29
-40
lines changed

3 files changed

+29
-40
lines changed

solution/0600-0699/0626.Exchange Seats/README.md

+12-17
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,36 @@ Seat 表:
6666
### **SQL**
6767

6868
```sql
69-
SELECT
70-
s1.id,
71-
COALESCE ( s2.student, s1.student ) AS student
69+
# Write your MySQL query statement below
70+
SELECT s1.id, COALESCE(s2.student, s1.student) AS student
7271
FROM
73-
seat s1
74-
LEFT JOIN seat s2 ON ( s1.id + 1 ) ^ 1 - 1 = s2.id
75-
ORDER BY
76-
s1.id;
72+
Seat AS s1
73+
LEFT JOIN Seat AS s2 ON (s1.id + 1) ^ 1 - 1 = s2.id
74+
ORDER BY 1;
7775
```
7876

7977
```sql
78+
# Write your MySQL query statement below
8079
SELECT
8180
id + (
8281
CASE
8382
WHEN id % 2 = 1
84-
AND id != (SELECT MAX(id) FROM seat) THEN 1
83+
AND id != (SELECT MAX(id) FROM Seat) THEN 1
8584
WHEN id % 2 = 0 THEN -1
8685
ELSE 0
8786
END
8887
) AS id,
8988
student
90-
FROM seat
91-
ORDER BY id;
89+
FROM Seat
90+
ORDER BY 1;
9291
```
9392

9493
```sql
9594
# Write your MySQL query statement below
96-
select
97-
RANK() over(
98-
order by
99-
(id -1) ^ 1
100-
) as id,
95+
SELECT
96+
RANK() OVER (ORDER BY (id - 1) ^ 1) AS id,
10197
student
102-
from
103-
seat
98+
FROM Seat;
10499
```
105100

106101
```sql

solution/0600-0699/0626.Exchange Seats/README_EN.md

+12-17
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,36 @@ Note that if the number of students is odd, there is no need to change the last
6262
### **SQL**
6363

6464
```sql
65-
SELECT
66-
s1.id,
67-
COALESCE ( s2.student, s1.student ) AS student
65+
# Write your MySQL query statement below
66+
SELECT s1.id, COALESCE(s2.student, s1.student) AS student
6867
FROM
69-
seat s1
70-
LEFT JOIN seat s2 ON ( s1.id + 1 ) ^ 1 - 1 = s2.id
71-
ORDER BY
72-
s1.id;
68+
Seat AS s1
69+
LEFT JOIN Seat AS s2 ON (s1.id + 1) ^ 1 - 1 = s2.id
70+
ORDER BY 1;
7371
```
7472

7573
```sql
74+
# Write your MySQL query statement below
7675
SELECT
7776
id + (
7877
CASE
7978
WHEN id % 2 = 1
80-
AND id != (SELECT MAX(id) FROM seat) THEN 1
79+
AND id != (SELECT MAX(id) FROM Seat) THEN 1
8180
WHEN id % 2 = 0 THEN -1
8281
ELSE 0
8382
END
8483
) AS id,
8584
student
86-
FROM seat
87-
ORDER BY id;
85+
FROM Seat
86+
ORDER BY 1;
8887
```
8988

9089
```sql
9190
# Write your MySQL query statement below
92-
select
93-
RANK() over(
94-
order by
95-
(id -1) ^ 1
96-
) as id,
91+
SELECT
92+
RANK() OVER (ORDER BY (id - 1) ^ 1) AS id,
9793
student
98-
from
99-
seat
94+
FROM Seat;
10095
```
10196

10297
```sql
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
SELECT
2-
s1.id,
3-
COALESCE(s2.student, s1.student) AS student
1+
# Write your MySQL query statement below
2+
SELECT s1.id, COALESCE(s2.student, s1.student) AS student
43
FROM
5-
seat AS s1
6-
LEFT JOIN seat AS s2 ON (s1.id + 1) ^ 1 - 1 = s2.id
7-
ORDER BY s1.id;
4+
Seat AS s1
5+
LEFT JOIN Seat AS s2 ON (s1.id + 1) ^ 1 - 1 = s2.id
6+
ORDER BY 1;

0 commit comments

Comments
 (0)