Skip to content

Commit 216ce67

Browse files
committed
LeetCode 614~1050 mysql
1 parent 8d46967 commit 216ce67

File tree

26 files changed

+210
-268
lines changed

26 files changed

+210
-268
lines changed

solution/0600-0699/0614.Second Degree Follower/README.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@ None
1313

1414
<!-- tabs:start -->
1515

16-
### **Python3**
17-
<!-- 这里可写当前语言的特殊实现逻辑 -->
16+
### **SQL**
1817

19-
```python
20-
21-
```
22-
23-
### **Java**
24-
<!-- 这里可写当前语言的特殊实现逻辑 -->
25-
26-
```java
27-
28-
```
29-
30-
### **...**
3118
```
32-
19+
SELECT followee AS follower,
20+
count(distinct(follower)) AS num
21+
FROM follow
22+
WHERE followee IN
23+
(SELECT follower
24+
FROM follow)
25+
GROUP BY followee
26+
ORDER BY followee
3327
```
3428

35-
<!-- tabs:end -->
29+
<!-- tabs:end -->

solution/0600-0699/0614.Second Degree Follower/README_EN.md

+10-14
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,17 @@ None
1111

1212
<!-- tabs:start -->
1313

14-
### **Python3**
14+
### **SQL**
1515

16-
```python
17-
18-
```
19-
20-
### **Java**
21-
22-
```java
23-
24-
```
25-
26-
### **...**
2716
```
28-
17+
SELECT followee AS follower,
18+
count(distinct(follower)) AS num
19+
FROM follow
20+
WHERE followee IN
21+
(SELECT follower
22+
FROM follow)
23+
GROUP BY followee
24+
ORDER BY followee
2925
```
3026

31-
<!-- tabs:end -->
27+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT followee AS follower,
2+
count(distinct(follower)) AS num
3+
FROM follow
4+
WHERE followee IN
5+
(SELECT follower
6+
FROM follow)
7+
GROUP BY followee
8+
ORDER BY followee

solution/0600-0699/0615.Average Salary Departments VS Company/README.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,10 @@ None
1313

1414
<!-- tabs:start -->
1515

16-
### **Python3**
17-
<!-- 这里可写当前语言的特殊实现逻辑 -->
16+
### **SQL**
1817

19-
```python
20-
21-
```
22-
23-
### **Java**
24-
<!-- 这里可写当前语言的特殊实现逻辑 -->
25-
26-
```java
27-
28-
```
29-
30-
### **...**
3118
```
3219
3320
```
3421

35-
<!-- tabs:end -->
22+
<!-- tabs:end -->

solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md

+2-13
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,10 @@ None
1111

1212
<!-- tabs:start -->
1313

14-
### **Python3**
14+
### **SQL**
1515

16-
```python
17-
18-
```
19-
20-
### **Java**
21-
22-
```java
23-
24-
```
25-
26-
### **...**
2716
```
2817
2918
```
3019

31-
<!-- tabs:end -->
20+
<!-- tabs:end -->

solution/0600-0699/0618.Students Report By Geography/README.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@ None
1313

1414
<!-- tabs:start -->
1515

16-
### **Python3**
17-
<!-- 这里可写当前语言的特殊实现逻辑 -->
16+
### **SQL**
1817

19-
```python
20-
21-
```
22-
23-
### **Java**
24-
<!-- 这里可写当前语言的特殊实现逻辑 -->
25-
26-
```java
27-
28-
```
29-
30-
### **...**
3118
```
32-
19+
SELECT MAX(CASE
20+
WHEN continent = 'America' THEN name
21+
END) AS America, MAX(CASE
22+
WHEN continent = 'Asia' THEN name
23+
END) AS Asia
24+
, MAX(CASE
25+
WHEN continent = 'Europe' THEN name
26+
END) AS Europe
27+
FROM (
28+
SELECT name, continent, row_number() OVER (PARTITION BY continent ORDER BY name) AS rk
29+
FROM student
30+
) t
31+
GROUP BY rk
3332
```
3433

35-
<!-- tabs:end -->
34+
<!-- tabs:end -->

solution/0600-0699/0618.Students Report By Geography/README_EN.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ None
1111

1212
<!-- tabs:start -->
1313

14-
### **Python3**
14+
### **SQL**
1515

16-
```python
17-
18-
```
19-
20-
### **Java**
21-
22-
```java
23-
24-
```
25-
26-
### **...**
2716
```
28-
17+
SELECT MAX(CASE
18+
WHEN continent = 'America' THEN name
19+
END) AS America, MAX(CASE
20+
WHEN continent = 'Asia' THEN name
21+
END) AS Asia
22+
, MAX(CASE
23+
WHEN continent = 'Europe' THEN name
24+
END) AS Europe
25+
FROM (
26+
SELECT name, continent, row_number() OVER (PARTITION BY continent ORDER BY name) AS rk
27+
FROM student
28+
) t
29+
GROUP BY rk
2930
```
3031

31-
<!-- tabs:end -->
32+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SELECT MAX(CASE
2+
WHEN continent = 'America' THEN name
3+
END) AS America, MAX(CASE
4+
WHEN continent = 'Asia' THEN name
5+
END) AS Asia
6+
, MAX(CASE
7+
WHEN continent = 'Europe' THEN name
8+
END) AS Europe
9+
FROM (
10+
SELECT name, continent, row_number() OVER (PARTITION BY continent ORDER BY name) AS rk
11+
FROM student
12+
) t
13+
GROUP BY rk

solution/0600-0699/0619.Biggest Single Number/README.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@ None
1313

1414
<!-- tabs:start -->
1515

16-
### **Python3**
17-
<!-- 这里可写当前语言的特殊实现逻辑 -->
16+
### **SQL**
1817

19-
```python
20-
21-
```
22-
23-
### **Java**
24-
<!-- 这里可写当前语言的特殊实现逻辑 -->
25-
26-
```java
27-
28-
```
29-
30-
### **...**
3118
```
32-
19+
SELECT (
20+
SELECT num
21+
FROM my_numbers
22+
GROUP BY num
23+
HAVING COUNT(*) = 1
24+
ORDER BY num DESC
25+
LIMIT 1
26+
) AS num
3327
```
3428

35-
<!-- tabs:end -->
29+
<!-- tabs:end -->

solution/0600-0699/0619.Biggest Single Number/README_EN.md

+10-14
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,17 @@ None
1111

1212
<!-- tabs:start -->
1313

14-
### **Python3**
14+
### **SQL**
1515

16-
```python
17-
18-
```
19-
20-
### **Java**
21-
22-
```java
23-
24-
```
25-
26-
### **...**
2716
```
28-
17+
SELECT (
18+
SELECT num
19+
FROM my_numbers
20+
GROUP BY num
21+
HAVING COUNT(*) = 1
22+
ORDER BY num DESC
23+
LIMIT 1
24+
) AS num
2925
```
3026

31-
<!-- tabs:end -->
27+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT (
2+
SELECT num
3+
FROM my_numbers
4+
GROUP BY num
5+
HAVING COUNT(*) = 1
6+
ORDER BY num DESC
7+
LIMIT 1
8+
) AS num

solution/0600-0699/0620.Not Boring Movies/README.md

+7-16
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,14 @@
4545

4646
<!-- tabs:start -->
4747

48-
### **Python3**
49-
<!-- 这里可写当前语言的特殊实现逻辑 -->
48+
### **SQL**
5049

51-
```python
52-
53-
```
54-
55-
### **Java**
56-
<!-- 这里可写当前语言的特殊实现逻辑 -->
57-
58-
```java
59-
60-
```
61-
62-
### **...**
6350
```
64-
51+
SELECT *
52+
FROM cinema
53+
WHERE description NOT LIKE '%boring%'
54+
AND mod(id,2)=1
55+
ORDER BY rating desc;
6556
```
6657

67-
<!-- tabs:end -->
58+
<!-- tabs:end -->

solution/0600-0699/0620.Not Boring Movies/README_EN.md

+7-14
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,14 @@ For the example above, the output should be:
7171

7272
<!-- tabs:start -->
7373

74-
### **Python3**
74+
### **SQL**
7575

76-
```python
77-
78-
```
79-
80-
### **Java**
81-
82-
```java
83-
84-
```
85-
86-
### **...**
8776
```
88-
77+
SELECT *
78+
FROM cinema
79+
WHERE description NOT LIKE '%boring%'
80+
AND mod(id,2)=1
81+
ORDER BY rating desc;
8982
```
9083

91-
<!-- tabs:end -->
84+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT *
2+
FROM cinema
3+
WHERE description NOT LIKE '%boring%'
4+
AND mod(id,2)=1
5+
ORDER BY rating desc;

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

+9-16
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,16 @@
5353

5454
<!-- tabs:start -->
5555

56-
### **Python3**
57-
<!-- 这里可写当前语言的特殊实现逻辑 -->
56+
### **SQL**
5857

59-
```python
60-
61-
```
62-
63-
### **Java**
64-
<!-- 这里可写当前语言的特殊实现逻辑 -->
65-
66-
```java
67-
68-
```
69-
70-
### **...**
7158
```
72-
59+
SELECT
60+
s1.id, COALESCE(s2.student, s1.student) AS student
61+
FROM
62+
seat s1
63+
LEFT JOIN
64+
seat s2 ON (s1.id+1)^1-1 = s2.id
65+
ORDER BY s1.id;
7366
```
7467

75-
<!-- tabs:end -->
68+
<!-- tabs:end -->

0 commit comments

Comments
 (0)