我想要sum()一些列。但是没有用。这是错误ORA-00937 请帮帮我。
查询
SELECT MB.COUNTRY_CODE, /* Error ORA-00937 This line */
MB.OPERATOR_NAME AS COUNTRY_NAME,
C.PMN_CODE AS OPERATOR_NAME,
(C.RANG_START / 1024) AS RANG_START,
(C.RANG_END / 1024) AS RANG_END,
COUNT(*) AS TRANSACTION_BY_OPER,
'0' AS TERMINATE_CHARGE,
SUM(C.RATE * (COUNT(*))) AS TRANSIT_CHARGE
FROM IR_V_IMM_RATE_BY_CDR C
LEFT JOIN IR_PMN_MASTER_BROKER MB
ON C.COMPANY_CODE = MB.COMPANY_CODE
AND C.PMN_DOMAIN = MB.PMN_CODE
LEFT JOIN IR_PMN_INTER_SERVICE S
ON C.PMN_DOMAIN = S.PMN_CODE
AND C.COMPANY_CODE = S.COMPANY_CODE
WHERE C.SUB_EVENT_TYPE_ID = '2'
AND C.MODIFIER = 'P2P'
AND S.INTER_SERVICE = 'MMS'
AND C.COMPANY_CODE = 'AIS'
AND C.EVENT_TYPE_ID = '602'
AND C.PMN_DOMAIN = 'AICEN'
AND TO_CHAR(C.CUTOFF_DATE, 'MM/YYYY') = '04/2015'
GROUP BY MB.COUNTRY_CODE, MB.OPERATOR_NAME, C.PMN_CODE, C.RANG_START,
C.RANG_END, C.RATE
如果删除3行。这是工作
COUNT(*) AS TRANSACTION_BY_OPER,
'0' AS TERMINATE_CHARGE,
SUM(C.RATE * (COUNT(*))) AS TRANSIT_CHARGE
....
...
/* Fix If delete 3 line */
GROUP BY MB.COUNTRY_CODE, MB.OPERATOR_NAME,C.PMN_CODE,C.RANG_START,C.RANG_END
现在,我想在此查询中添加3行。但错误ORA-00937
提前谢谢。 ;)答案 0 :(得分:0)
SELECT MB.COUNTRY_CODE, /* Error ORA-00937 This line */
MB.OPERATOR_NAME AS COUNTRY_NAME,
C.PMN_CODE AS OPERATOR_NAME,
(C.RANG_START / 1024) AS RANG_START,
(C.RANG_END / 1024) AS RANG_END,
COUNT(*) AS TRANSACTION_BY_OPER,
'0' AS TERMINATE_CHARGE,
SUM(C.RATE * (COUNT(*))) AS TRANSIT_CHARGE
FROM IR_V_IMM_RATE_BY_CDR C
LEFT JOIN IR_PMN_MASTER_BROKER MB
ON C.COMPANY_CODE = MB.COMPANY_CODE
AND C.PMN_DOMAIN = MB.PMN_CODE
LEFT JOIN IR_PMN_INTER_SERVICE S
ON C.PMN_DOMAIN = S.PMN_CODE
AND C.COMPANY_CODE = S.COMPANY_CODE
WHERE C.SUB_EVENT_TYPE_ID = '2'
AND C.MODIFIER = 'P2P'
AND S.INTER_SERVICE = 'MMS'
AND C.COMPANY_CODE = 'AIS'
AND C.EVENT_TYPE_ID = '602'
AND C.PMN_DOMAIN = 'AICEN'
AND TO_CHAR(C.CUTOFF_DATE, 'MM/YYYY') = '04/2015'
GROUP BY MB.COUNTRY_CODE, MB.OPERATOR_NAME, C.PMN_CODE, C.RANG_START,
C.RANG_END,'0'
您包含'0'
并且它未包含在分组中,并且它既不是聚合函数。同时从group by中删除C.Rate
,因为它正在使用内部聚合函数Sum
。尝试此
答案 1 :(得分:0)
你有:
SUM(C.RATE * (COUNT(*))) AS TRANSIT_CHARGE
嵌套聚合函数(通常)不起作用。你可能只想要:
SUM(C.RATE) AS TRANSIT_CHARGE
这会将group by
之前生成的行的所有费率相加。