Skip to content

Commit 22e6363

Browse files
authored
feat: add sql solutions to lc problems: No.1731,1867,1988 (#1063)
* No.1731.The Number of Employees Which Report to Each Employee * No.1867.Orders With Maximum Quantity Above Average * No.1988.Find Cutoff Score for Each School
1 parent a459916 commit 22e6363

File tree

9 files changed

+57
-7
lines changed

9 files changed

+57
-7
lines changed

solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ SELECT
6969
FROM
7070
Employees AS e1
7171
JOIN Employees AS e2 ON e1.reports_to = e2.employee_id
72-
WHERE e2.employee_id IS NOT NULL
7372
GROUP BY e2.employee_id
7473
ORDER BY e2.employee_id;
7574
```

solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ SELECT
6868
FROM
6969
Employees AS e1
7070
JOIN Employees AS e2 ON e1.reports_to = e2.employee_id
71-
WHERE e2.employee_id IS NOT NULL
7271
GROUP BY e2.employee_id
7372
ORDER BY e2.employee_id;
7473
```

solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/Solution.sql

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ SELECT
77
FROM
88
Employees AS e1
99
JOIN Employees AS e2 ON e1.reports_to = e2.employee_id
10-
WHERE e2.employee_id IS NOT NULL
1110
GROUP BY e2.employee_id
1211
ORDER BY e2.employee_id;

solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,19 @@ OrdersDetails 表:
9494
<!-- 这里可写当前语言的特殊实现逻辑 -->
9595

9696
```sql
97-
97+
# Write your MySQL query statement below
98+
WITH
99+
t AS (
100+
SELECT
101+
order_id,
102+
max(quantity) AS max_quantity,
103+
sum(quantity) / count(1) AS avg_quantity
104+
FROM OrdersDetails
105+
GROUP BY order_id
106+
)
107+
SELECT order_id
108+
FROM t
109+
WHERE max_quantity > (SELECT max(avg_quantity) FROM t);
98110
```
99111

100112
<!-- tabs:end -->

solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,19 @@ Orders 1 and 3 are imbalanced because they have a maximum quantity that exceeds
8787
### **SQL**
8888

8989
```sql
90-
90+
# Write your MySQL query statement below
91+
WITH
92+
t AS (
93+
SELECT
94+
order_id,
95+
max(quantity) AS max_quantity,
96+
sum(quantity) / count(1) AS avg_quantity
97+
FROM OrdersDetails
98+
GROUP BY order_id
99+
)
100+
SELECT order_id
101+
FROM t
102+
WHERE max_quantity > (SELECT max(avg_quantity) FROM t);
91103
```
92104

93105
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Write your MySQL query statement below
2+
WITH
3+
t AS (
4+
SELECT
5+
order_id,
6+
max(quantity) AS max_quantity,
7+
sum(quantity) / count(1) AS avg_quantity
8+
FROM OrdersDetails
9+
GROUP BY order_id
10+
)
11+
SELECT order_id
12+
FROM t
13+
WHERE max_quantity > (SELECT max(avg_quantity) FROM t);

solution/1900-1999/1988.Find Cutoff Score for Each School/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ Exam 表:
9999
<!-- 这里可写当前语言的特殊实现逻辑 -->
100100

101101
```sql
102-
102+
# Write your MySQL query statement below
103+
SELECT school_id, min(ifnull(score, -1)) AS score
104+
FROM
105+
Schools AS s
106+
LEFT JOIN Exam AS e ON s.capacity >= e.student_count
107+
GROUP BY school_id;
103108
```
104109

105110
<!-- tabs:end -->

solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ Exam table:
9696
### **SQL**
9797

9898
```sql
99-
99+
# Write your MySQL query statement below
100+
SELECT school_id, min(ifnull(score, -1)) AS score
101+
FROM
102+
Schools AS s
103+
LEFT JOIN Exam AS e ON s.capacity >= e.student_count
104+
GROUP BY school_id;
100105
```
101106

102107
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write your MySQL query statement below
2+
SELECT school_id, min(ifnull(score, -1)) AS score
3+
FROM
4+
Schools AS s
5+
LEFT JOIN Exam AS e ON s.capacity >= e.student_count
6+
GROUP BY school_id;

0 commit comments

Comments
 (0)