Hive中count统计数量的多种使用方式

本文介绍如何在Hive中使用count函数结合casewhen、distinct等进行复杂的数据统计,包括对不同条件下的数据进行计数,适用于日常数据分析场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

其他环境没有试,Hive上肯定是可以的。
可以在count里使用case when、distinct等处理,满足日常数据统计需求。

select
      pt_day,
      count(*),
      count(uid),count(identifier),
      count(distinct uid),count(distinct identifier),
      count(case when appkey='CSIos' then identifier else null end),count(case when appkey='CSAndroid' then identifier else null end),
      count(distinct case when appkey='CSIos' then identifier else null end),count(distinct case when appkey='CSAndroid' then identifier else null end),
      count(case when appkey in ('CSIos','CSAndroid') then identifier else null end),
      count(distinct case when appkey in ('CSIos','CSAndroid') then identifier else null end)
 from bi_all_access_log
where pt_day between '2017-11-01' and '2017-11-14'
group by pt_day
order by pt_day;
说明:
其中,count(*),count(uid),count(identifier)三都统计得到的值是相同的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值