Skip to content

Commit 3400c71

Browse files
authored
Create find-the-quiet-students-in-all-exams.sql
1 parent 04ff946 commit 3400c71

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)