Skip to content

Commit 4ea9e02

Browse files
committed
LeetCode 500~600 mysql
1 parent 69cc60f commit 4ea9e02

File tree

33 files changed

+300
-123
lines changed

33 files changed

+300
-123
lines changed

solution/0500-0599/0550.Game Play Analysis IV/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ None
1616
### **SQL**
1717

1818
```
19-
19+
(select round(count(distinct (b.player_id)) / (select count(distinct (player_id)) from Activity), 2) as fraction
20+
from Activity a
21+
left join (select player_id, min(event_date) as first_date from Activity group by player_id) as b
22+
on a.player_id = b.player_id and datediff(a.event_date, b.first_date) = 1)
2023
```
2124

2225
<!-- tabs:end -->

solution/0500-0599/0550.Game Play Analysis IV/README_EN.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ None
1414
### **SQL**
1515

1616
```
17-
17+
(select round(count(distinct (b.player_id)) / (select count(distinct (player_id)) from Activity), 2) as fraction
18+
from Activity a
19+
left join (select player_id, min(event_date) as first_date from Activity group by player_id) as b
20+
on a.player_id = b.player_id and datediff(a.event_date, b.first_date) = 1)
1821
```
1922

2023
<!-- tabs:end -->
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(select round(count(distinct (b.player_id)) / (select count(distinct (player_id)) from Activity), 2) as fraction
2+
from Activity a
3+
left join (select player_id, min(event_date) as first_date from Activity group by player_id) as b
4+
on a.player_id = b.player_id and datediff(a.event_date, b.first_date) = 1)

solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ None
1616
### **SQL**
1717

1818
```
19-
19+
SELECT Name
20+
FROM Employee
21+
WHERE Id IN
22+
(SELECT ManagerId
23+
FROM Employee
24+
GROUP BY ManagerId
25+
HAVING count(*) >= 5)
2026
```
2127

2228
<!-- tabs:end -->

solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ None
1414
### **SQL**
1515

1616
```
17-
17+
SELECT Name
18+
FROM Employee
19+
WHERE Id IN
20+
(SELECT ManagerId
21+
FROM Employee
22+
GROUP BY ManagerId
23+
HAVING count(*) >= 5)
1824
```
1925

2026
<!-- tabs:end -->
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT Name
2+
FROM Employee
3+
WHERE Id IN
4+
(SELECT ManagerId
5+
FROM Employee
6+
GROUP BY ManagerId
7+
HAVING count(*) >= 5)

solution/0500-0599/0574.Winning Candidate/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ None
1616
### **SQL**
1717

1818
```
19-
19+
SELECT Name
20+
FROM Candidate,
21+
(SELECT CandidateId,
22+
count(*) AS total
23+
FROM Vote
24+
GROUP BY CandidateId
25+
ORDER BY total DESC limit 1) AS tmp
26+
WHERE Candidate.id = tmp.CandidateId
2027
```
2128

2229
<!-- tabs:end -->

solution/0500-0599/0574.Winning Candidate/README_EN.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ None
1414
### **SQL**
1515

1616
```
17-
17+
SELECT Name
18+
FROM Candidate,
19+
(SELECT CandidateId,
20+
count(*) AS total
21+
FROM Vote
22+
GROUP BY CandidateId
23+
ORDER BY total DESC limit 1) AS tmp
24+
WHERE Candidate.id = tmp.CandidateId
1825
```
1926

2027
<!-- tabs:end -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT Name
2+
FROM Candidate,
3+
(SELECT CandidateId,
4+
count(*) AS total
5+
FROM Vote
6+
GROUP BY CandidateId
7+
ORDER BY total DESC limit 1) AS tmp
8+
WHERE Candidate.id = tmp.CandidateId

solution/0500-0599/0577.Employee Bonus/README.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@ 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 name,
20+
bonus
21+
FROM Employee e
22+
LEFT JOIN Bonus b
23+
ON e.empId = b.empId
24+
WHERE (b.bonus < 1000
25+
OR b.bonus is null)
3326
```
3427

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

0 commit comments

Comments
 (0)