We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 04ff946 commit 3400c71Copy full SHA for 3400c71
MySQL/find-the-quiet-students-in-all-exams.sql
@@ -0,0 +1,26 @@
1
+# Time: O(m + nlogn)
2
+# Space: O(m + n)
3
+
4
+SELECT s.student_id,
5
+ s.student_name
6
+FROM student s
7
+ INNER JOIN (SELECT a.student_id,
8
+ Count(a.exam_id) AS total_exam,
9
+ Sum(CASE
10
+ WHEN a.score > min_score
11
+ AND a.score < max_score THEN 1
12
+ ELSE 0
13
+ END) AS quite_exam
14
+ FROM exam a
15
+ INNER JOIN (SELECT exam_id,
16
+ Min(score) AS min_score,
17
+ Max(score) AS max_score
18
+ FROM exam
19
+ GROUP BY exam_id
20
+ ORDER BY NULL) b
21
+ ON a.exam_id = b.exam_id
22
+ GROUP BY a.student_id
23
+ ORDER BY NULL) c
24
+ ON s.student_id = c.student_id
25
+WHERE c.total_exam = c.quite_exam
26
+ORDER BY s.student_id;
0 commit comments