1

这是我的 oracle 查询:

SELECT      DISTINCT Student.student_id, student_name, SUM(credit)
FROM        Student, Class, Enrolls
WHERE       Student.student_id = Enrolls.student_id
AND         Class.schedule_num = Enrolls.schedule_num
AND         Class.semester = Enrolls.semester
AND         grade != 'F'
AND         grade IS NOT null
ORDER BY    student_id ASC;

查询工作正常,直到我添加SUM(credit). 之后我得到:

ORA-00937: not a single-group group function

请帮忙,谢谢。

4

2 回答 2

6

您的 SQL 语句中似乎缺少该GROUP BY子句。它应该看起来像:

SELECT      Student.student_id, student_name, SUM(credit)
FROM        Student, Class, Enrolls
WHERE       Student.student_id = Enrolls.student_id
AND         Class.schedule_num = Enrolls.schedule_num
AND         Class.semester = Enrolls.semester
AND         grade != 'F'
AND         grade IS NOT null
GROUP BY    Student.student_id, student_name
ORDER BY    student_id ASC;
于 2013-10-29T02:46:57.300 回答
0

像这样试试

SELECT      DISTINCT s.student_id, student_name, SUM(credit)
FROM        Student s, 
            CLASS c, 
            Enrolls e
WHERE       s.student_id = e.student_id
AND         c.schedule_num = e.schedule_num
AND         c.semester = e.semester
AND         grade != 'F'
AND         grade IS NOT NULL
GROUP BY    s.student_id, student_name
ORDER BY    student_id ASC;

您在查询中遗漏了GROUP BY子句,如果您想要总和,则需要按 student_id 和 student_name 分组。

于 2013-10-29T02:51:00.887 回答