Skip to content

Practice Students and Examinations

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1280
LeetCode Problem

Students and Examinations

Problem Statement

Tables: Students(student_id INT, student_name VARCHAR); Subjects(subject_name VARCHAR); Examinations(student_id INT, subject_name VARCHAR). Students.student_id and Subjects.subject_name are unique. Examinations permits duplicates, with each row recording one exam attendance. Every student takes every listed subject. Return student_id, student_name, subject_name and attended_exams for every student-subject pair, including zero attendances. Count repeated examination rows. Order by student_id ascending, then subject_name ascending.

Source: Students and Examinations on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Students table: +------------+--------------+ | student_id | student_name | +------------+--------------+ | 1          | Alice        | | 2          | Bob          | | 13         | John         | | 6          | Alex         | +------------+--------------+ Subjects table: +--------------+ | subject_name | +--------------+ | Math         | | Physics      | | Programming  | +--------------+ Examinations table: +------------+--------------+ | student_id | subject_name | +------------+--------------+ | 1          | Math         | | 1          | Physics      | | 1          | Programming  | | 2          | Programming  | | 1          | Physics      | | 1          | Math         | | 13         | Math         | | 13         | Programming  | | 13         | Physics      | | 2          | Math         | | 1          | Math         | +------------+--------------+
Output
+------------+--------------+--------------+----------------+ | student_id | student_name | subject_name | attended_exams | +------------+--------------+--------------+----------------+ | 1          | Alice        | Math         | 3              | | 1          | Alice        | Physics      | 2              | | 1          | Alice        | Programming  | 1              | | 2          | Bob          | Math         | 1              | | 2          | Bob          | Physics      | 0              | | 2          | Bob          | Programming  | 1              | | 6          | Alex         | Math         | 0              | | 6          | Alex         | Physics      | 0              | | 6          | Alex         | Programming  | 0              | | 13         | John         | Math         | 1              | | 13         | John         | Physics      | 1              | | 13         | John         | Programming  | 1              | +------------+--------------+--------------+----------------+

Related LeetCode Problems

Practice more problems similar to Students and Examinations.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.