我为查询找到了丢失的关键字错误ORA-00905
SELECT '01_AMT' AS FIELD, COUNT((NVL(AMT,0)) AS CNT FROM TBL1
UNION ALL
SELECT
CASE
WHEN AMT IS NULL THEN 'NULL'
WHEN AMT<10000 THEN '<10000'
WHEN AMT>= 10000 and AMT<=59999 THEN '10,000-59,999’
ELSE '60,000up' END,
COUNT (1) CNT FROM TBL1
GROUP BY CASE
WHEN AMT IS NULL THEN 'NULL'
WHEN AMT<10000 THEN '<10000'
WHEN AMT>= 10000 and AMT<=59999 THEN '10,000-59,999’
ELSE '60,000up' END
输出:
FIELD CNT
01_Amt 100000
10,000-59,999 50000
60,000up 50000
第一个字段&#39; 01-Amt&#39;应该具有第二行中其他计数的总计数和细分。 Amt是数字数据类型。
答案 0 :(得分:0)
你没有使用标准的结束标记,而是那个卷曲标记。 Oracle不理解它,它忽略了句子的其余部分。校正:
SELECT '01_AMT' AS FIELD, COUNT((NVL(AMT,0)) AS CNT FROM TBL1
UNION ALL
SELECT
CASE
WHEN AMT IS NULL THEN 'NULL'
WHEN AMT<10000 THEN '<10000'
WHEN AMT>= 10000 and AMT<=59999 THEN '10,000-59,999' <= CHANGED THIS TICK!
ELSE '60,000up' END,
COUNT (1) CNT FROM TBL1
GROUP BY CASE
WHEN AMT IS NULL THEN 'NULL'
WHEN AMT<10000 THEN '<10000'
WHEN AMT>= 10000 and AMT<=59999 THEN '10,000-59,999' <= CHANGED THIS TICK!
ELSE '60,000up' END