gpt4 book ai didi

mysql - Impala 中 SELECT 语句的算术运算

转载 作者:行者123 更新时间:2023-11-29 21:48:08 24 4
gpt4 key购买 nike

我正在编写一个查询,需要按行的类型进行分组,并将值除以总数以了解 IMPALA 中总数的百分比。例如:

Name                           performance
something type1 something 15
something type1 something 18
something type2 something 23
something something something 345
something type2 something 23

SELECT
CASE WHEN name like '%type1%' then 'type 1'
WHEN name like '%type2%' then 'type2'
ELSE 'other' END as type
,sum(performance) / (SELECT sum(performance) FROM table)
FROM table
GROUP BY type

这给了我一个 AnalysisException 错误:选择列表中不支持子查询。谁能告诉我如何解决这个问题?

最佳答案

我认为它只需要“()”

SELECT
(CASE WHEN name like '%type1%' then 'type 1'
WHEN name like '%type2%' then 'type2'
Else 'other' END) as type
,sum(performance) / (SELECT sum(performance) FROM table)
FROM Table
GROUP BY type

关于mysql - Impala 中 SELECT 语句的算术运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com