如何计算配置单元分区表中的值

svmlkihl  于 2021-06-27  发布在  Hive
关注(0)|答案(2)|浏览(251)

我有一个2列的分区表 (country,status) 现在我要数一数 SUCCESS 以及 ERROR 时间 status 列。我该如何解决这个问题?

5t7ly7z5

5t7ly7z51#

带有聚合的用例语句:

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 列,如果您需要总计数。

gv8xihay

gv8xihay2#

您可以使用where条件来获得结果
从..中选择计数(状态)。。其中status='成功';联合选择计数(状态)自。。其中status='错误';

相关问题