from 关键字未在 case 语句中的预期位置找到

from keyword not found where expected in case statement

我有一个查询,写在下面。我收到错误。我已经添加了双引号。还是行不通。请建议我。

SELECT  

TO_DATE(TO_CHAR(BATCH_CREATION_TIME,'YYYY/MM/DD'),'YYYY/MM/DD') AS CREATION_DATE, 
SUM(DECODE(CDR_ACTUAL_COUNT,NULL,0,CDR_ACTUAL_COUNT)) AS CCOLLECTED,
SUM(DECODE(CDR_ACTUAL_COUNT,NULL,0,CDR_ACTUAL_COUNT)) - SUM(DECODE(CDR_PARSE_ERROR_COUNT,NULL,0,CDR_PARSE_ERROR_COUNT))  
- SUM(DECODE(CDR_DISCARD_COUNT,NULL,0,CDR_DISCARD_COUNT)) AS COLLECTED,
SUM(DECODE(VALIDATION_CNR_COUNT,NULL,0,VALIDATION_CNR_COUNT)) + SUM(DECODE(VALIDATION_CE_COUNT,NULL,0,VALIDATION_CE_COUNT))   
+ SUM(DECODE(VALIDATION_CR_COUNT,NULL,0,VALIDATION_CR_COUNT)) + SUM(DECODE(VALIDATION_NCR_COUNT,NULL,0,VALIDATION_NCR_COUNT))  AS ERRORED, 
SUM(DECODE(VALIDATION_RNC_COUNT,NULL,0,VALIDATION_RNC_COUNT)) + SUM(DECODE(VALIDATION_RV_COUNT,NULL,0,VALIDATION_RV_COUNT)) AS PROCESSED 
"CDR_SOURCE_TYPE" =
CASE
WHEN CDR_SOURCE_TYPE IN ('SMSC') THEN DECODE(NETWORK_TYPE,'CDMA','SMSC_CDMA','HSPA','SMSC_HSPA') AS "CDR_SOURCE_TYPE"
WHEN CDR_SOURCE_TYPE IN ('P_GW') and BATCH_ID like '%_PGW_%' and BATCH_ID like '%_PGW_REPLAY_%' THEN 'PGW_REPLAY' AS "CDR_SOURCE_TYPE"
WHEN CDR_SOURCE_TYPE IN ('OCS_UDR','OCS_EDR','OCS_CDMA_EDR','OCS_UDR_RECOVER','MACH_UDR','AAA','PTT_CDMA','OCS_CDMA_UDR','MTX') THEN "CDR_SOURCE_TYPE"
--ELSE 'Excelent'
END

FROM  BATCH_SUMMARY

WHERE                 
BATCH_CREATION_TIME BETWEEN TO_DATE(TO_CHAR(sysdate,'YYYY-MM-DD') ||' 00:00:00', 'YYYY-MM-DD HH24:MI:SS')  
AND TO_DATE(TO_CHAR(sysdate,'YYYY-MM-DD') ||' 23:59:59', 'YYYY-MM-DD HH24:MI:SS') 
AND BATCH_CREATION_TIME < (SYSDATE -1/24)
--and CDR_SOURCE_TYPE IN ('OCS_UDR','OCS_EDR','OCS_CDMA_EDR','OCS_UDR_RECOVER','MACH_UDR','AAA','PTT_CDMA','OCS_CDMA_UDR','MTX')

GROUP BY 
TO_DATE(TO_CHAR(BATCH_CREATION_TIME,'YYYY/MM/DD'),'YYYY/MM/DD'), CDR_SOURCE_TYPE 

这里只关注case语句,而不是做

"CDR_SOURCE_TYPE" = (your case statement)

(your case statement) as 'CDR_SOURCE_TYPE'

似乎缺少 comma

您还需要在 group by 中使用整个 case 语句,而不是单独使用列名

SELECT
To_date(To_char(BATCH_CREATION_TIME,'YYYY/MM/DD'),'YYYY/MM/DD') AS CREATION_DATE,
Sum(Decode(CDR_ACTUAL_COUNT,NULL,0,CDR_ACTUAL_COUNT)) AS CCOLLECTED,
Sum(Decode(CDR_ACTUAL_COUNT,NULL,0,CDR_ACTUAL_COUNT)) - Sum(Decode(CDR_PARSE_ERROR_COUNT,NULL,0,CDR_PARSE_ERROR_COUNT))
- Sum(Decode(CDR_DISCARD_COUNT,NULL,0,CDR_DISCARD_COUNT)) AS COLLECTED,
Sum(Decode(VALIDATION_CNR_COUNT,NULL,0,VALIDATION_CNR_COUNT)) + Sum(Decode(VALIDATION_CE_COUNT,NULL,0,VALIDATION_CE_COUNT))
+ Sum(Decode(VALIDATION_CR_COUNT,NULL,0,VALIDATION_CR_COUNT)) + Sum(Decode(VALIDATION_NCR_COUNT,NULL,0,VALIDATION_NCR_COUNT))  AS ERRORED,
Sum(Decode(VALIDATION_RNC_COUNT,NULL,0,VALIDATION_RNC_COUNT)) + Sum(Decode(VALIDATION_RV_COUNT,NULL,0,VALIDATION_RV_COUNT)) AS PROCESSED ,

CASE
WHEN CDR_SOURCE_TYPE IN ('SMSC') THEN Decode(NETWORK_TYPE,'CDMA','SMSC_CDMA','HSPA','SMSC_HSPA')
WHEN CDR_SOURCE_TYPE IN ('P_GW') AND BATCH_ID LIKE '%_PGW_%' AND BATCH_ID LIKE '%_PGW_REPLAY_%' THEN 'PGW_REPLAY'
WHEN CDR_SOURCE_TYPE IN ('OCS_UDR','OCS_EDR','OCS_CDMA_EDR','OCS_UDR_RECOVER','MACH_UDR','AAA','PTT_CDMA','OCS_CDMA_UDR','MTX') THEN CDR_SOURCE_TYPE
--ELSE 'Excelent'
END AS CDR_SOURCE_TYPE
FROM  BATCH_SUMMARY

WHERE
BATCH_CREATION_TIME BETWEEN To_date(To_char(sysdate,'YYYY-MM-DD') ||' 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
AND To_date(To_char(sysdate,'YYYY-MM-DD') ||' 23:59:59', 'YYYY-MM-DD HH24:MI:SS')
AND BATCH_CREATION_TIME < (SYSDATE -1/24)
--and CDR_SOURCE_TYPE IN ('OCS_UDR','OCS_EDR','OCS_CDMA_EDR','OCS_UDR_RECOVER','MACH_UDR','AAA','PTT_CDMA','OCS_CDMA_UDR','MTX')

GROUP BY
TO_DATE(TO_CHAR(BATCH_CREATION_TIME,'YYYY/MM/DD'),'YYYY/MM/DD'), 
CASE
WHEN CDR_SOURCE_TYPE IN ('SMSC') THEN Decode(NETWORK_TYPE,'CDMA','SMSC_CDMA','HSPA','SMSC_HSPA') AS "CDR_SOURCE_TYPE"
WHEN CDR_SOURCE_TYPE IN ('P_GW') AND BATCH_ID LIKE '%_PGW_%' AND BATCH_ID LIKE '%_PGW_REPLAY_%' THEN 'PGW_REPLAY' AS "CDR_SOURCE_TYPE"
WHEN CDR_SOURCE_TYPE IN ('OCS_UDR','OCS_EDR','OCS_CDMA_EDR','OCS_UDR_RECOVER','MACH_UDR','AAA','PTT_CDMA','OCS_CDMA_UDR','MTX') THEN "CDR_SOURCE_TYPE"
--ELSE 'Excelent'
END

还要确保您的数据库支持 Aliasname=column_name 格式。在 Sql 服务器中它会工作。否则使用

Column_name as Aliasname 

更新:

SELECT CASE -- CDR_SOURCE_TYPE removed
         WHEN CDR_SOURCE_TYPE IN ( 'SMSC' ) THEN Decode(NETWORK_TYPE, 'CDMA', 'SMSC_CDMA',
                                                                      'HSPA', 'SMSC_HSPA')
         WHEN CDR_SOURCE_TYPE IN ( 'P_GW' )
              AND BATCH_ID LIKE '%_PGW_%'
              AND BATCH_ID LIKE '%_PGW_REPLAY_%' THEN 'PGW_REPLAY'
       END
FROM   BATCH_SUMMARY