oracle ORA-00934: 00934. 00000 此处不允许使用组功能 - “此处不允许使用组功能”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41231651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:21:06  来源:igfitidea点击:

ORA-00934: group function is not allowed here 00934. 00000 - "group function is not allowed here"

sqloracleselectsum

提问by Rega Schardijn

The question is: give per office(kantoor) which have the total salary greater that 15000, give the average salary and the office name. use the inner join with using clausule

问题是:给出总工资大于 15000 的每个办公室(kantoor),给出平均工资和办公室名称。使用内连接和 using clausule

This is my current query:

这是我当前的查询:

SELECT      OFF.OFFICENR,
            OFF.NAME AS OFFICE,
            AVG(SAL)
FROM        OFFICE OFF INNER JOIN EMPLOYEE EMP USING (OFFICENR)
WHERE       SUM((SAL) >= 15000)                 **<---line 29**
GROUP BY    OFF.OFFICENR, OFF.NAME;      

the query output is:

查询输出是:

ORA-00934: group function is not allowed here 00934. 00000 - "group function is not allowed here" *Cause:
*Action: Error at Line: 29 Column: 13

ORA-00934: 00934. 00000 - “此处不允许使用组功能” *原因:
*操作:第 29 行错误:第 13 列

回答by Siyual

You should use HAVINGfor this:

您应该HAVING为此使用:

SELECT      OFF.OFFICENR,
            OFF.NAME AS OFFICE,
            AVG(SAL)
FROM        OFFICE OFF 
INNER JOIN  EMPLOYEE EMP USING (OFFICENR)
GROUP BY    OFF.OFFICENR, OFF.NAME
HAVING      SUM(SAL) >= 15000;

回答by Md Aktaruzzaman

Should have use 'Group By' and 'Having' clause

应该使用“Group By”和“Having”子句