Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please help figuring out how to get this query.

Author  Topic 

vannuge
Starting Member

1 Post

Posted - 2011-02-17 : 00:50:29
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 *, AVG(Grade) AS GPA
FROM Students S1
JOIN Transcripts USING (studentID)
JOIN sections USING (sectionID)
JOIN courses USING (deptID)
WHERE courses.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. Thank you.

here is the schema.
http://pic80.picturetrail.com/VOL966/3750032/21784981/395200168.jpg

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-17 : 00:57:44
are you using MySQL or Microsoft SQL Server ?

SQLTeam is on SQL Server only. For MySQL, try dbforums.com


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -