Skip to content
C

Duplicate Enrollments

Mediumsql

A student should not be able to enroll in the same course in the same semester twice — (student_id, course_id, semester) is meant to be a composite candidate key on enrollments, but it isn't enforced yet. Write a query returning student_id, course_id, semester, and a cnt column, for every combination that appears more than once.

sql
CREATE TABLE enrollments ( student_id INTEGER NOT NULL, course_id INTEGER NOT NULL, semester TEXT NOT NULL );

Sample data (this is what your query runs against when you press Run):

sql
INSERT INTO enrollments (student_id, course_id, semester) VALUES (1, 101, 'Fall2025'), (1, 102, 'Fall2025'), (2, 101, 'Fall2025'), (1, 101, 'Fall2025'), (2, 102, 'Spring2026'), (3, 101, 'Fall2025');

Input (stdin)

Output

Run your code to see output here...