Impala 中 SELECT 语句的算术运算

Posted

技术标签:

【中文标题】Impala 中 SELECT 语句的算术运算【英文标题】:Arithmetic operation with SELECT statements in Impala 【发布时间】:2015-11-25 17:14:03 【问题描述】:

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

【问题讨论】:

我不明白你是不是真的从同一张表中提取:sum(performance) / (SELECT sum(performance) FROM table) FROM table 【参考方案1】:

我认为它只需要“()”

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

【讨论】:

以上是关于Impala 中 SELECT 语句的算术运算的主要内容,如果未能解决你的问题,请参考以下文章