Jacobvu84 / sql-basic-advance

SQL
0 stars 0 forks source link

Find the number of times each student attended each exam #6

Open Jacobvu84 opened 6 months ago

Jacobvu84 commented 6 months ago

image

SELECT 
    s.student_id, 
    s.student_name, 
    u.subject_name, 
    COUNT(e.subject_name) AS attended_exams
FROM Students s
JOIN Subjects u
LEFT JOIN Examinations e ON s.student_id = e.student_id AND u.subject_name = e.subject_name
GROUP BY s.student_id, u.subject_name
ORDER BY s.student_id, u.subject_name;