Leetcode Problem 1280. Students and Examinations

1280. Students and Examinations

Leetcode Solutions

Group by and Cross Join to Count Exam Attendance

  1. Perform a cross join between the Students and Subjects tables to create all possible combinations of students and subjects.
  2. Group the Examinations table by student_id and subject_name and count the occurrences to get the number of attended exams.
  3. Left join the cross-joined table with the grouped examination counts using student_id and subject_name as keys.
  4. Use IFNULL or a similar function to replace null values in the attended_exams column with zero.
  5. Order the final result by student_id and subject_name.
erDiagram
    Students {
        int student_id PK
        varchar student_name
    }
    Subjects {
        varchar subject_name PK
    }
    Examinations {
        int student_id
        varchar subject_name
    }

Nothing

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...