我正在编写一个查询,该查询需要以行类型为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错误:选择列表中不支持子查询。
谁能建议我该如何解决这个问题?

最佳答案

我认为只需要“()”

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/

10-16 01:48