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

Lines changed: 10 additions & 16 deletions
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

Lines changed: 10 additions & 14 deletions
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 -->
Lines changed: 8 additions & 0 deletions
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

Lines changed: 2 additions & 15 deletions
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

Lines changed: 2 additions & 13 deletions
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

Lines changed: 15 additions & 16 deletions
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

Lines changed: 15 additions & 14 deletions
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 -->
Lines changed: 13 additions & 0 deletions
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

Lines changed: 10 additions & 16 deletions
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

Lines changed: 10 additions & 14 deletions
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 -->

0 commit comments

Comments
 (0)