Skip to content
CampusEduX

Preserve student occurrences with zero participation

Mediumsql
Learn the Concept: Entity

Return every studentid and enrollmentcount. Include students with no enrollment as zero and count each supplied enrollment occurrence separately.

MySQL dialect.

sql
CREATE TABLE students (student_id INT PRIMARY KEY, student_name VARCHAR(80) NOT NULL); CREATE TABLE enrollments (enrollment_id INT PRIMARY KEY, student_id INT NOT NULL); INSERT INTO students VALUES (1,'Asha'),(2,'Asha'),(3,'Mira'); INSERT INTO enrollments VALUES (1,1),(2,1),(3,2);

Required ordering: Ascending student_id.

Edge cases:

  • Repeated names remain separate identities.
  • A student can have zero or several relationships.

Related Problems

Input (stdin)

Output

Run your code to see output here...