File tree 9 files changed +57
-7
lines changed
1700-1799/1731.The Number of Employees Which Report to Each Employee
1800-1899/1867.Orders With Maximum Quantity Above Average
1900-1999/1988.Find Cutoff Score for Each School
9 files changed +57
-7
lines changed Original file line number Diff line number Diff line change 69
69
FROM
70
70
Employees AS e1
71
71
JOIN Employees AS e2 ON e1 .reports_to = e2 .employee_id
72
- WHERE e2 .employee_id IS NOT NULL
73
72
GROUP BY e2 .employee_id
74
73
ORDER BY e2 .employee_id ;
75
74
```
Original file line number Diff line number Diff line change 68
68
FROM
69
69
Employees AS e1
70
70
JOIN Employees AS e2 ON e1 .reports_to = e2 .employee_id
71
- WHERE e2 .employee_id IS NOT NULL
72
71
GROUP BY e2 .employee_id
73
72
ORDER BY e2 .employee_id ;
74
73
```
Original file line number Diff line number Diff line change 7
7
FROM
8
8
Employees AS e1
9
9
JOIN Employees AS e2 ON e1 .reports_to = e2 .employee_id
10
- WHERE e2 .employee_id IS NOT NULL
11
10
GROUP BY e2 .employee_id
12
11
ORDER BY e2 .employee_id ;
Original file line number Diff line number Diff line change @@ -94,7 +94,19 @@ OrdersDetails 表:
94
94
<!-- 这里可写当前语言的特殊实现逻辑 -->
95
95
96
96
``` 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);
98
110
```
99
111
100
112
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -87,7 +87,19 @@ Orders 1 and 3 are imbalanced because they have a maximum quantity that exceeds
87
87
### ** SQL**
88
88
89
89
``` 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);
91
103
```
92
104
93
105
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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);
Original file line number Diff line number Diff line change @@ -99,7 +99,12 @@ Exam 表:
99
99
<!-- 这里可写当前语言的特殊实现逻辑 -->
100
100
101
101
``` 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;
103
108
```
104
109
105
110
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -96,7 +96,12 @@ Exam table:
96
96
### ** SQL**
97
97
98
98
``` 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;
100
105
```
101
106
102
107
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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;
You can’t perform that action at this time.
0 commit comments