So I'm trying to use the right SQL commands to solve this question..
"return the top 5 students with the highest major GPA (Grade Point Average). Major GPA is determined by the courses taught in a student’s home department and has the attribute Core=1." as a single query.
I tried the following with no luck.
SELECT s1.name,s1.deptID,avg(grade) as GPA
FROM
Transcripts
JOIN Students s1 using (studentID)
JOIN Departments D1 USING (deptID)
JOIN Sections USING (sectionID)
JOIN Courses USING (deptID)
JOIN Departments D2 ON (Courses.deptID=D2.deptID)
WHERE D1.deptID=D2.deptID AND core=1
GROUP BY s1.studentid
ORDER by GPA DESC
LIMIT 5
;
What am I doing wrong? The WHERE course.core=1 seems to not be doing anything for me. To clarify, I'm trying to only average the grades that are core=1. Any help is greatly appreciated. Thank you.
here is the schema.
http://pic80.picturetrail.com/VOL966.../395200168.jpg