这是我的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
请帮助,谢谢。
答案 0 :(得分: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;
答案 1 :(得分: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。