我正在完成这项任务,我需要计算每个学生的CGPA,以及成绩*学分/总学分的公式。
select
round(sum((grade.grade*course.credits)/count(course.courseno)),1),
student.studentNo
from
course, grade, student, offering
where
student.studentno = grade.studentno
and course.courseno = offering.courseno
and offering.offerno = grade.offerno
group by
student.studentNo;
我有点无法继续,因为我不知道这有什么不对。
编辑:所以我做了一些改变,你们指出但我仍然遇到麻烦select grade.studentno,
(select sum (t)
from(select(grade*credits)/count(offering.courseno)
from student s2, grade g2, offering o2, course c2
where s2.studentno=g2.studentno
and g2.offerno=o2.offerno
and o2.courseno=c2.courseno
group by g2.studentno
) t
)
from student, grade, offering, course
where student.studentno=grade.studentno
and grade.offerno=offering.offerno
and offering.courseno=course.courseno
group by grade.studentno;
错误
代码1054:未知栏名在'字段列表中提供courseno'
它无法识别子计数中的聚合' count'
答案 0 :(得分:0)
不允许将聚合函数嵌套在同一个SELECT中,例如SUM(X/COUNT(Y))
。当需要嵌套时,可以使用子查询执行一个,然后使用外部查询执行另一个;这通常是必要的,因为这种情况通常需要不同的分组标准。
答案 1 :(得分:0)
除ONLY_FULL_GROUP_BY模式外,不允许将聚合函数嵌套在同一个SELECT中。您可以使用子查询来选择与此
类似的两列 select round(sum((grade.grade*course.credits)/count(course.courseno)),1) from (select student.studentNo from course, grade, student, offering where student.studentno=grade.studentno and course.courseno=offering.courseno and offering.offerno=grade.offerno) group by student.studentNo;