[코드카타] SQL 27 Students and Examinations

Data_Student·2024년 11월 11일
0

코드카타

목록 보기
34/57

[코드카타] SQL 27 Students and Examinations

27. Students and Examinations
https://leetcode.com/problems/students-and-examinations/

Write a solution to find the number of times each student attended each exam.
Return the result table ordered by student_id and subject_name.
select s.student_id, student_name, j.subject_name , count(e.student_id) attended_exams
from students s cross join subjects j
left join examinations e on s.student_id=e.student_id and j.subject_name=e.subject_name
group by 1,2,3
order by 1
Cross join의 개념 숙지하기!
처음 Cross join없이 join만 했을 때에도 동작했던 오류가 발생했었음..
그래도 cross join으로 합친 후에 count(e.student_id)로 정확한 수를 카운트하기!
count() 내의 컬럼을 다르게 하면 답이 달라질 수 있음!

0개의 댓글