I have tables:
Student(sID, firstName, lastName, email, cgpa)
Course(cNum, name, dept, credit)
Offering(oID, cNum, dept, year, term, instructor)
Took(sID, oID, grade)
I'm trying to complete the question:
Find all courses for the term 2017F and the current enrolment
I currently have this query to grab the number of students enrolled in each course:
SELECT Took.oID, COUNT(*) AS enrolment
FROM Took
GROUP BY Took.oID
HAVING COUNT(*) > 0
Nested inside of this statement to grab the correct courses that I want the enrolment counts for:
SELECT oID
FROM Offering
WHERE Offering.year = 2017
AND Offering.term = 'F'
Both of which are nested inside of this query to tie everything together:
SELECT DISTINCT Offering.cNum, Course.name, (I WOULD LIKE COUNT(*) AS enrolment HERE)
FROM Offering NATURAL JOIN Course
WHERE Offering.oID IN (
SELECT oID
FROM Offering
WHERE Offering.year = 2017
AND Offering.term = 'F'
AND oID IN (
SELECT Took.oID, COUNT(*) AS enrolment
FROM Took
GROUP BY Took.oID
HAVING COUNT(*) > 0))
GROUP BY Offering.cNum, Course.name;
My question is, how can I pass the resulting COUNT(*) AS enrolment from the furthest nested query to the initial query so that it can be displayed in the resulting projection? (This is homework)