获取oracle错误而不是GROUP BY表达式

时间:2014-03-25 21:05:00

标签: sql oracle group-by

我在创建视图时得到的不是表达式,我得到的错误就是这一行" param.ports_per_olt8 * SUM(card.in_svc_ind)AS total_port_cnt,"有什么帮助吗?

我的参数如下所示

WITH param
    AS (SELECT eid,
                 17-SUM(DECODE(NVL(EQUIPPED_TYPE, ASSIGNED_TYPE),'ETOS10',1,0)) AS gpon_slots_per_ta500X,
               8 AS ports_per_olt8,
               4 AS etos10_slots_per_ta5000, 
               10 AS ports_per_etos10,
                8 as ports_per_TA1108VP  
      FROM ECIL_TA500X_CARD
      GROUP BY EID) 


            (  SELECT   card.eid,
                    COUNT ( * ) AS installed_card_cnt, 
                    SUM (card.in_svc_ind) AS insrv_card_cnt, 
                    param.ports_per_olt8 * SUM (card.in_svc_ind) 
                    AS total_port_cnt,  --ERROR HERE--
                    (param.ports_per_olt8 * SUM (card.in_svc_ind))
                    - SUM (DECODE (card.in_svc_ind, 1, card.oos_port_cnt, 0))
                       AS insrv_port_cnt
             FROM   ecil_ta500x_card card, param  
            WHERE   card.equipped_type like 'OLT8%'
            AND     card.eid = param.eid 
           GROUP BY   card.eid) oltcard,

ECIL_TA500X_CARD是一个表格,并在此视图中创建参数

1 个答案:

答案 0 :(得分:2)

param.ports_per_olt8列不是任何聚合的一部分,这就是您收到此错误的原因。如果它对每一行都有一个不同的值,我认为它有 - 尝试使用MIN(param.ports_per_olt8),无论使用哪一列。

WITH param
    AS (SELECT eid,
                 17-SUM(DECODE(NVL(EQUIPPED_TYPE, ASSIGNED_TYPE),'ETOS10',1,0)) AS gpon_slots_per_ta500X,
               8 AS ports_per_olt8,
               4 AS etos10_slots_per_ta5000, 
               10 AS ports_per_etos10,
                8 as ports_per_TA1108VP  
      FROM ECIL_TA500X_CARD
      GROUP BY EID) 


            (  SELECT   card.eid,
                    COUNT ( * ) AS installed_card_cnt, 
                    SUM (card.in_svc_ind) AS insrv_card_cnt, 
                    MIN(param.ports_per_olt8) * SUM (card.in_svc_ind) 
                    AS total_port_cnt,  --ERROR HERE--
                    (MIN(param.ports_per_olt8) * SUM (card.in_svc_ind))
                    - SUM (DECODE (card.in_svc_ind, 1, card.oos_port_cnt, 0))
                       AS insrv_port_cnt
             FROM   ecil_ta500x_card card, param  
            WHERE   card.equipped_type like 'OLT8%'
            AND     card.eid = param.eid 
           GROUP BY   card.eid) oltcard,