2012-04-02 45 views
2

我想搜索類型爲「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'; 

回答

9

你需要一個 「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; 
+0

完美!謝了哥們 – user1308955 2012-04-02 20:17:40

1
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的一個盲目的規則。