GROUP BY显示错误的结果

时间:2012-09-01 11:25:59

标签: sql oracle

这会返回2条记录,但第二行的总和显示为null,有什么问题?

SELECT nvl(X_CDTR_AGT_ID_2AND,' ')

      ,COUNT(CASE P_PMNT_SRC WHEN 'FDR_ATM' THEN 1 END) as atmCount

      ,( SELECT sum(X_STTLM_AMT) AS IVRSUM
           FROM v_minf_report b 
           WHERE b.X_CDTR_AGT_ID_2AND = ass.X_CDTR_AGT_ID_2AND  
           GROUP BY X_CDTR_AGT_ID_2AND ) as nyun

      ,COUNT(CASE P_PMNT_SRC WHEN 'FDR_INB' THEN 1 END) as inbCount
      ,COUNT(CASE P_PMNT_SRC WHEN 'FDR_IVR' THEN 1 END) as ivrCount
      ,COUNT(CASE P_PMNT_SRC WHEN 'FDR_BV' THEN 1 END) as bvcount
      ,COUNT(CASE P_PMNT_SRC WHEN 'FDR_MANUAL' THEN 1 END) as manualcount

FROM v_minf_report ass
WHERE P_TX_CTGY = 'CTO'
GROUP BY X_CDTR_AGT_ID_2AND

1 个答案:

答案 0 :(得分:0)

SELECT
 X_CDTR_AGT_ID_2AND, atmCount, IVRSUM, inbCount, ivrCount, bvcount, manualcount
FROM (
 SELECT nvl(X_CDTR_AGT_ID_2AND,' ') X_CDTR_AGT_ID_2AND,
 COUNT(CASE P_PMNT_SRC WHEN 'FDR_ATM' THEN 1 END) as atmCount,
 COUNT(CASE P_PMNT_SRC WHEN 'FDR_INB' THEN 1 END) as inbCount,
 COUNT(CASE P_PMNT_SRC WHEN 'FDR_IVR' THEN 1 END) as ivrCount,
 COUNT(CASE P_PMNT_SRC WHEN 'FDR_BV' THEN 1 END) as bvcount,
 COUNT(CASE P_PMNT_SRC WHEN 'FDR_MANUAL' THEN 1 END) as manualcount
 FROM v_minf_report
 WHERE P_TX_CTGY = 'CTO'
 group by X_CDTR_AGT_ID_2AND
) as ass JOIN (
 SELECT nvl(X_CDTR_AGT_ID_2AND,' ') X_CDTR_AGT_ID_2AND,
 sum(X_STTLM_AMT) AS IVRSUM
 from v_minf_report 
 GROUP BY X_CDTR_AGT_ID_2AND
) as nyun USING(X_CDTR_AGT_ID_2AND)