Skip to content

Instantly share code, notes, and snippets.

@mlivingston40
Created March 30, 2024 17:11
Show Gist options
  • Save mlivingston40/bc0bb591fedd28153852858baa1da860 to your computer and use it in GitHub Desktop.
Save mlivingston40/bc0bb591fedd28153852858baa1da860 to your computer and use it in GitHub Desktop.
find all exams by student by subjects
-- Write your PostgreSQL query statement below
select
s.student_id,
s.student_name,
j.subject_name,
sum(case when e.subject_name is null then 0 else 1 end) as attended_exams
from
Students s
Cross join Subjects j
left join Examinations e
on e.student_id = s.student_id and e.subject_name = j.subject_name
group by 1,2,3
order by 1,3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment