Students and Examinations

2pts
Microsoft

Problem Statement

Academic administrators need a comprehensive overview of exam attendance. The report must show every student paired with every subject, even if the student never attended an exam for that specific subject.

Write an SQL query to find the number of times each student attended each exam.

Rules:

  • The result must include every student from the Students table and every subject from the Subjects table.
  • For student-subject pairs with no attendance, the count should be 0.
  • Return the student_id, student_name, subject_name, and attended_exams.
  • Results must be sorted by student_id and subject_name in ascending order.
Tests your understanding of
Basic SQL, CROSS JOIN, LEFT JOIN, Aggregation and NULL Handling

Input Tables

students
student_id(INTEGER)student_name(VARCHAR)
1Alice
2Bob
13John
6Alex
subjects
subject_name(VARCHAR)
Math
Physics
Programming
examinations
student_id(INTEGER)subject_name(VARCHAR)
1Math
1Physics
1Programming
1Physics
1Math
1Math
2Programming
1Physics
1Math
13Math
13Programming
13Physics
2Math
1Math

Expected Output

student_id(INTEGER)student_name(VARCHAR)subject_name(VARCHAR)attended_exams(INTEGER)
1AliceMath5
1AlicePhysics3
1AliceProgramming1
2BobMath1
2BobPhysics0
2BobProgramming1
6AlexMath0
6AlexPhysics0
6AlexProgramming0
13JohnMath1
13JohnPhysics1
13JohnProgramming1

Tags

EasyBasic SQLCROSS JOINLEFT JOINAggregationNULL Handling
15-20 min
68%

Hints