find ids of students who have repeated a course

by Yolanda Cruickshank 10 min read

How to get the number of students registered for more than 5?

To get the number of students who are registered for more than 5 courses you do this... SELECT COUNT(*) FROM REGISTRATION WHERE SEMESTER = 'GIVEN SEMESTER' GROUP BY CAMPUS, STUDENT_ID HAVING COUNT(*) > 5; You need to group by campus AND student id since student id is repeated for different campuses.

How do I get the number of students in a course?

To get the number of students you can count the number of rows that query returns: SELECT COUNT(*) AS total FROM ( SELECT student_id FROM yourtable WHERE Semester = .... GROUP BY student_id HAVING COUNT(DISTINCT Course) > 5 )

How to get all students that have taken more than 5 courses?

Use GROUP BYand HAVING COUNTto get all the students that have taken more than five courses: SELECT student_id FROM yourtable WHERE Semester = .... GROUP BY student_id HAVING COUNT(DISTINCT Course) > 5

How to group students by semester number?

SELECT COUNT(*) FROM REGISTRATION WHERE SEMESTER = 'GIVEN SEMESTER' GROUP BY CAMPUS, STUDENT_ID HAVING COUNT(*) > 5; You need to group by campus AND student id since student id is repeated for different campuses. Also, the primary key should be composite (campus, student_id, semester, year, course) if I understand you correctly. Share