在impala中使用select语句进行算术运算

mrfwxfqh  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(330)

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

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错误:选择列表中不支持子查询。有人能告诉我如何处理这个问题吗?

cigdeys3

cigdeys31#

我想它只需要“()”

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

相关问题