Skip to content

Commit e674cf2

Browse files
authored
Create subqueries-in-FROM-clause.sql
1 parent e29a3ed commit e674cf2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT s.name, exam_counts.course_name, exam_counts.exam_count
2+
FROM Student s
3+
JOIN (
4+
SELECT e.student_id, c.name AS course_name, COUNT(*) AS exam_count
5+
FROM Exam e
6+
JOIN Course c ON e.course_id = c.id
7+
GROUP BY e.student_id, c.name
8+
HAVING COUNT(*) = (
9+
SELECT MAX(exam_count)
10+
FROM (
11+
SELECT student_id, course_id, COUNT(*) AS exam_count
12+
FROM Exam
13+
GROUP BY student_id, course_id
14+
) max_counts
15+
WHERE max_counts.student_id = e.student_id
16+
)
17+
) exam_counts ON s.id = exam_counts.student_id;

0 commit comments

Comments
 (0)