ORA-00937:不是单组组功能错误

时间:2014-11-19 06:00:36

标签: sql oracle

我在我的sql中使用了4个表,所有这些都是必需的。但是我得到了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 个答案:

答案 0 :(得分:0)

尝试替换它:

 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

您的选择列表中有嵌套的总和。我想这会导致错误