ORA-00937: 不是单组组函数错误
Posted
技术标签:
【中文标题】ORA-00937: 不是单组组函数错误【英文标题】:ORA-00937: not a single-group group function error 【发布时间】:2014-11-19 06:00:36 【问题描述】:我在我的 sql 中使用了 4 个表,所有这些表都是 nessesary。但是我得到了 oracle 00937: 不是单组函数错误。请告诉我哪里错了
select SUBSTR(d_name,1,8) DNAME,
SUBSTR(s_name,1,10) SNAME,
bd.bill_year*100+bd.bill_month BILL_MTH,
COUNT(CASE WHEN bd.TARIFF_CODE IN(50,55,56) THEN bd.CONSUMER_NUMBER END) IND_CNT,
NVL(SUM(CASE WHEN bd.TARIFF_CODE IN(50,55,56) THEN SUM(energy_units_ind+energy_units_com+energy_units_dom) END),0) IND_UNT,
NVL(SUM(CASE WHEN bd.TARIFF_CODE IN(50,55,56) THEN SUM(TOS_CHARGE) END),0) IND_TOS
from bill_details bd,billing_inputs bi,consumer_master cm,bult b /* here i am using 4 tables */
where
bd.bill_year*100+bd.bill_month=201410
and bd.bill_year*100+bd.bill_month=bi.bill_year*100+bi.bill_month
and cm.consumer_type='C'
and bd.consumer_number=cm.consumer_number
and bd.consumer_number=bi.consumer_no
and b.subdiv=cm.subdivision_code
and TOS_CHARGE > 0
GROUP BY SUBSTR(d_name,1,8),SUBSTR(s_name,1,10),bd.bill_year*100+bd.bill_month /*this group by not working */
order by SUBSTR(d_name,1,8),SUBSTR(s_name,1,10),bd.bill_year*100+bd.bill_month
/
【问题讨论】:
【参考方案1】:尝试替换这个:
NVL(SUM(CASE WHEN bd.TARIFF_CODE IN(50,55,56) and TOS_CHARGE >0 THEN SUM(energy_units_ind+energy_units_com+energy_units_dom) END),0) IND_UNT,
NVL(SUM(CASE WHEN bd.TARIFF_CODE IN(50,55,56) and TOS_CHARGE >0 THEN SUM(TOS_CHARGE) END),0) IND_TOS
与:
NVL(SUM(CASE WHEN bd.TARIFF_CODE IN(50,55,56) and TOS_CHARGE > 0 THEN energy_units_ind+energy_units_com+energy_units_dom END),0) IND_UNT,
NVL(SUM(CASE WHEN bd.TARIFF_CODE IN(50,55,56) and TOS_CHARGE > 0 THEN TOS_CHARGE END),0) IND_TOS
您的选择列表中有嵌套的总和。我想这会导致错误
【讨论】:
以上是关于ORA-00937: 不是单组组函数错误的主要内容,如果未能解决你的问题,请参考以下文章
ORA-00937: 不是单组分组函数,已在使用 group by