Oracle SQL ORA-00937:不是单组功能
问题描述:
我想搜索类型为“Savings”的帐户,但以下代码段提供了错误“ORA-00937:不是单个组组功能“ - 有谁知道为什么我得到这个错误?Oracle SQL 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';
答
你需要一个 “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;
答
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:你除了聚合函数SELECT子句中使用哪种列应该出现在GROUP BY clause.It的一个盲目的规则。
完美!谢了哥们 – user1308955 2012-04-02 20:17:40