hive 查询去除空值,将HIVE查询结果中的空值或NULL值替换为特定值

当Hive查询的某一列没有返回结果时,想要显示默认值'Others'。例如,查询clicks_data表中非空country和os(agent)的数据并按这些字段分组。原始查询会得到包含空值的结果,通过使用LENGTH()函数和CASE WHEN语句,可以检查os(agent)的长度,当长度大于0时显示实际值,否则显示'Others'。修改后的查询能正确返回期望的结果。
摘要由CSDN通过智能技术生成

I'm trying to show a default value, "Others", when the query does not return any result for one of the selected columns. I'll show you the example.

This query returns an empty value for os(agent) SO (in the first row):

select country, os(agent) SO, count(*) from clicks_data

where country is not null and os(agent) is not null

group by country, os(agent);

Output:

ZA 4

ZA Android 4

ZA Mac 8

ZA Windows 5

Instead, I would like to get this result:

ZA Others 4

ZA Android 4

ZA Mac 8

ZA Windows 5

My next attempt was this query, but it's not really working, either:

select country, regexp_replace(os(agent),'','Others') SO, count(*) from clicks_data

where country is not null and os(agent) is not null

group by country, os(ag

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值