Oracle SQL ORA-00937:不是单组组函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9983170/
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
Oracle SQL ORA-00937: not a single-group group function
提问by user1308955
I am trying to search for accounts which are of type 'Savings' but the following extract of code is giving me error "ORA-00937: not a single-group group function" - does anyone know why I am getting this error?
我正在尝试搜索类型为“Savings”的帐户,但以下代码摘录给了我错误“ORA-00937:不是单组组功能” - 有谁知道我为什么会收到此错误?
SELECT b.bID as "Branch Number", COUNT(a.accNum) as "# of Saving Accounts"
from branchtable b, accounttable a
where a.bId = b.bID
and a.acctype = 'Savings';
回答by Tim Williams
You need a "group by" clause:
你需要一个“group by”子句:
SELECT b.bID as "Branch Number",
COUNT(a.accNum) as "# of Saving Accounts"
from
branchtable b, accounttable a
where
a.bId = b.bID and a.acctype = 'Savings'
group by b.bID;
回答by Teja
SELECT b.bID as "Branch Number", COUNT(a.accNum) as "# of Saving Accounts"
from branchtable b, accounttable a
where a.bId = b.bID
and a.acctype = 'Savings'
GROUP BY b.bID;
PS: Whatever columns you use in the SELECT clause except aggregate functions should be present in the GROUP BY clause.It's a blind rule.
PS:在 SELECT 子句中使用的任何列(聚合函数除外)都应该出现在 GROUP BY 子句中。这是一个盲规则。