【发布时间】:2020-03-03 11:16:49
【问题描述】:
我是这里的新手,在 HiveQL 中仍然面临很多问题,需要向大家咨询。我有一个名为 Vote Table 的表格,我想计算 A、B、C、D 的“是”票(抱歉,我无法发布图片,所以我将其作为链接发送)。
但在这里我只想将 A1,A2,A3,A4 的计数加在一起;对于 B,C 仍将单独计算。我期望的输出是
我试过的是
select
type,
count(
case
when type = 'A1' and vote = 'yes' then 1
when type = 'A2' and vote = 'yes' then 1
when type = 'A3' and vote = 'yes' then 1
when type = 'A4' and vote = 'yes' then 1
else vote = 'yes' then 1
)
from vote_table
where …
group by type
我也试过这种方式
if (type in ('A1', 'A2', 'A3', 'A4') and vote = 'yes' then count(*) else (if (vote = 'yes' then count(*)))) as cnt_yes
但两者都不起作用。所以,我想咨询一下这里的专家,有没有更好的方法呢?谢谢!
【问题讨论】:
-
请不要在问题标题中添加“SOLVED”。只需将答案标记为解决方案就足够了。
-
@NikosC。嗨尼科斯!好的,我知道了!感谢您的反馈!
标签: hive count grouping hiveql