【问题标题】:Oracle SQL ORA-00937: not a single-group group function [duplicate]Oracle SQL ORA-00937:不是单组组函数 [重复]
【发布时间】:2012-04-16 12:16:15
【问题描述】:

我正在尝试搜索“储蓄”类型的帐户,但以下代码摘录给我错误“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';

【问题讨论】:

    标签: sql oracle function group-by


    【解决方案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 子句中。这是一个盲规。

    【讨论】:

      【解决方案2】:

      您需要一个“分组依据”子句:

      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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-30
        • 1970-01-01
        相关资源
        最近更新 更多