Impala中使用SELECT语句的算术运算

时间:2015-11-25 17:14:03

标签: mysql hiveql impala

我正在编写一个需要GROUP BY行类型的查询,并将该值除以总计以了解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错误:选择列表中不支持子查询。 任何人都可以建议我如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我认为它只需要"()"

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