写入的查询:
CREATE TABLE CEREAL_LIST_TAB
CEREAL_DESC VARCHAR(10)NOT NULL
INSERT INTO CEREAL_LIST_TAB
SELECT
NVL(CASE WHEN INDICATOR >= '01' AND INDICATOR <= '05' THEN 'WHEAT'
ELSE CASE WHEN INDICATOR >= '06' AND INDICATOR <= '10' THEN 'RICE'
ELSE CASE WHEN INDICATOR >= '11' AND INDICATOR <= '15' THEN 'BARLEY'
ELSE CASE WHEN INDICATOR >= '16' AND INDICATOR <= '20' THEN 'OATS'
ELSE CASE WHEN INDICATOR = '21' AND INDICATOR = '22' THEN 'OTHER' END END END END END,' ')
COUNT (CASE WHEN REVENUE <'1000000' THEN KEY_FIELD END) as 'Less than $1M',
COUNT (CASE WHEN REVENUE >='1000000' AND REVENUE <='5000000' THEN KEY_FIELD END) as '$1M-$5M',
COUNT (CASE WHEN REVENUE >='5000001' AND REVENUE <='10000000' THEN KEY_FIELD END) as '$5M-$10M',
COUNT (CASE WHEN REVENUE >='10000001' AND REVENUE <='25000000' THEN KEY_FIELD END) as '$10M-$25M';
FROM TABLE_REVENUE
GROUP BY CEREAL_DESC
ORDER BY CEREAL_DESC;
预期结果:我需要计数的每一个谷物在每个收入桶中列出的查询,但它的抛出错误,请帮助让我知道我在哪里犯错误
1条答案
按热度按时间hk8txs481#
这里有很多东西,
CEREAL_DESC
,而无需NVL
"
之间编码,而不是'
SELECT
子句中创建CEREAL_DESC
AND在GROUP BY
子句中使用它,必须使用子查询或CTEa BETWEEN b and c
对我来说比a >= b and a <= c
更可读试试这个