Skip to content
Advertisement

Find students who take most courses SQL

Assume there’s a table students containing student id, semester id and number of courses taken in each semester:

How can I find students in each semester who took the largest number of courses?

Expected output would be:

I thought of using OVER PARTITION BY, but I’m not sure how to use it correctly with this type of query. What I got is not working as expected.

Advertisement

Answer

Your idea is good. Now that you have the students’ semester course counts along with the maximum semester course counts, compare the two:

Another approach would be to select all maximum semester course counts and then use this to get the students:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement