首页 > 解决方案 > 如何计算配置单元分区表中的值

问题描述

我有一个有 2 列的分区表,(country,status)现在我想计算列中的次数SUCCESSERROR次数status。我该如何解决这个问题?

标签: hivehiveql

解决方案


具有聚合的用例语句:

select country,
       sum(case when status='SUCCESS' then 1 end) cnt_SUCCESS,
       sum(case when status='ERROR'   then 1 end) cnt_ERROR
  from tablename
group by country;

如果您需要总计数,请group by country删除并列。country


推荐阅读