架构:
Student(studentid,name,age)
Course(coursename,dept)
enroll(studentid,course,grade)
我需要找到,对于每个年龄组的学生,找到他们所学的政治学和历史课程的平均成绩,并返回每个年龄组平均成绩最高的学生姓名
到目前为止,我的尝试是:
select max(grade), age, name
from (
select name, age, grade
from student s, (
select avg(grade) as grade, e.studentid
from enroll e
where dname in ('Political Sciences', 'History')
group by studentid
) as temp
where s.studentid = temp.studentid
) temp1
group by temp1.age;
我想知道它在逻辑上是否正确,而不是语法上。