2
SELECT ssn, fname, minit, lname, AVG(hours)
FROM EMPLOYEE, WORKS_ON
WHERE EMPLOYEE.ssn = WORKS_ON.essn
GROUP BY hours
ORDER BY AVG(hours) DESC

它显示 ORA-00979 错误:不是 GROUP BY 表达式

我想知道为什么它不起作用?顺便说一句,所有表都存在并且没有任何错误。它在 Oracle AE 11g ===========UPDATE========================== 请求的表

SSN FNAME   MINIT   LNAME   AVG(HOURS)
888665555   James   E   Borg    -
666884444   Ramesh  K   Narayan 40
999887777   Alicia  J   Zelaya  20
987987987   Ahmad   V   Jabbar  20
453453453   Joyce   A   English 20
123456789   John    B   Smith   20
987654321   Jennifer    S   Wallace 17.5
333445555   Franklin    T   Wong    7.33333333333333333333333333333333333333
4

3 回答 3

3

我认为您的意思GROUP BY是聚合列:

SELECT ssn, fname, minit, lname, AVG(hours)
FROM EMPLOYEE, WORKS_ON
WHERE EMPLOYEE.ssn = WORKS_ON.essn
GROUP BY ssn, fname, minit, lname
ORDER BY AVG(hours) DESC
于 2013-03-20T21:17:14.443 回答
3

我认为你的分组与你需要的完全相反。你要:

SELECT ssn, fname, minit, lname, AVG(hours)
FROM EMPLOYEE, WORKS_ON
WHERE EMPLOYEE.ssn = WORKS_ON.essn
GROUP BY ssn, fname, minit, lname
ORDER BY AVG(hours) DESC
于 2013-03-20T21:17:26.197 回答
2

由于您使用的是聚合函数AVG(hours),因此您需要对其余结果进行分组:

SELECT ssn, fname, minit, lname, AVG(hours)
FROM EMPLOYEE, WORKS_ON
WHERE EMPLOYEE.ssn = WORKS_ON.essn
GROUP BY ssn, fname, minit, lname
ORDER BY AVG(hours) DESC
于 2013-03-20T21:17:12.490 回答