Skip to content

Commit ea9b687

Browse files
authored
Create students-and-examinations.sql
1 parent 8b3e647 commit ea9b687

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

MySQL/students-and-examinations.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O((m * n) * log(m * n))
2+
# Space: O(m * n)
3+
4+
SELECT a.student_id,
5+
a.student_name,
6+
b.subject_name,
7+
Count(c.subject_name) AS attended_exams
8+
FROM students AS a
9+
CROSS JOIN subjects AS b
10+
LEFT JOIN examinations AS c
11+
ON a.student_id = c.student_id
12+
AND b.subject_name = c.subject_name
13+
GROUP BY a.student_id,
14+
b.subject_name
15+
ORDER BY a.student_id,
16+
b.subject_name;

0 commit comments

Comments
 (0)