
😎풀이
- 학생의 아이디, 시험 과목, 해당 시험 과목의 응시 수를 조회
- CROSS JOIN을 통해
Subject
테이블과 Students
테이블을 결합
- LEFT JOIN을 통해
Examinations
테이블과 기존 테이블을 결합
3-1. 학생 아이디를 기준으로 결합
3-2. 시험 과목을 기준으로 결합
- 학생 아이디, 학생 이름, 과목명을 기준으로 그룹화
- 학생 아이디, 과목명을 기준으로 오름차 순 정렬하여 반환환
SELECT
s.student_id,
s.student_name,
sub.subject_name,
COUNT(e.subject_name) AS attended_exams
FROM Students s
CROSS JOIN Subjects sub
LEFT JOIN Examinations e
ON s.student_id = e.student_id
AND sub.subject_name = e.subject_name
GROUP BY s.student_id, s.student_name, sub.subject_name
ORDER BY s.student_id, sub.subject_name;