Lets say I have the following table:
Student Course University
1 a x
1 b x
1 c x
1 a y
2 a x
2 a y
2 a z
3 a x
For each student, I am trying to find the number of unique courses and universities that they are enrolled in.
The output would be as follows:
Student No. of Courses No. of Universities
1 3 2
2 1 3
3 1 1
How would I construct the SQL for this?
SELECT Student,
COUNT(DISTINCT Course) AS NumberOfCourses,
COUNT(DISTINCT University) AS NumberOfUniversities
FROM YourTable
GROUP BY Student
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With