我有桌子“学生”:
HTMLElement
如何选择GPA高于其课程和专业平均GPA的学生姓名?
非常感谢
答案 0 :(得分:-1)
这样的事情应该有效。在这里,我们计算每门课程和专业的平均值,加入学生并从那里过滤。
Select s.name
from students s
inner join
(Select course, speciality, avg(gpa) as avg_gpa from students
group by course, speciality) a
on a.course = s.course and a.speciality = s.speciality
where s.gpa > a.avg_gpa
答案 1 :(得分:-1)
SELECT name
FROM student s
INNER JOIN (
SELECT course , speciality , AVG(gpa) gpa
FROM student
GROUP BY course , speciality
) a ON s.course = a.course AND s.speciality = a.speciality
WHERE s.gpa > a.gpa