这是我的第一篇文章。希望我能说清楚:)
我尝试在impala上运行(使用hue)2版本的下一个查询。
版本1(按1分组):
SELECT payment_method,
(CASE WHEN price <= 1000 AND country = 'israel' THEN (price+50+0.18*price)/count(Distinct payment_token)/100
WHEN price <= 1000 AND country <> 'israel' THEN (price+50)/count(Distinct payment_token)/100
WHEN price > 1000 AND country = 'israel' THEN (price+0.05*price+0.18*price)/100
ELSE (price+0.05*price)/count(Distinct payment_token)/100
END) as ASP
FROM traffic_db.traffic_parq
WHERE year = 2016 AND month = 1
Group by 1
Error 1: AnalysisException: select list expression not produced by aggregation output (missing from GROUP BY clause?): CASE WHEN price... (rest of case when statment)
版本2(按1,2分组):
SELECT payment_method,
(CASE WHEN price <= 1000 AND country = 'israel' THEN (price+50+0.18*price)/count(Distinct payment_token)/100
WHEN price <= 1000 AND country <> 'israel' THEN (price+50)/count(Distinct payment_token)/100
WHEN price > 1000 AND country = 'israel' THEN (price+0.05*price+0.18*price)/100
ELSE (price+0.05*price)/count(Distinct payment_token)/100
END) as ASP
FROM traffic_db.traffic_parq
WHERE year = 2016 AND month = 1
Group by 1,2
Error: AnalysisException: GROUP BY expression must not contain aggregate functions: 2
我不知道发生了什么问题。注意:如果我运行 CASE-WHEN
带有非计算值的语句-工作正常(当我按case-when语句分组时)。
有人遇到过这种问题吗?
1条答案
按热度按时间r55awzrz1#
此查询的问题:
不是真正的
GROUP BY
条款。它是中的附加列select
不是聚合。你可以用以下方法修复它:(注意:我不知道impala是否允许在
group by
)关键是添加额外的未聚合列。所以,这可能就是你的目的。或者,可能需要条件聚合:
如果非要我猜的话,这就是你想做的。