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.
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 )
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
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