小编Seb*_*cre的帖子

将HIV或查询结果中的特定值替换为空值或NULL值

我正在尝试显示默认值"其他",当查询不返回所选列之一的任何结果时.我会告诉你这个例子.

此查询返回os(agent) SO(在第一行中)的空值:

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);
Run Code Online (Sandbox Code Playgroud)

输出:

ZA           4
ZA  Android  4
ZA  Mac      8
ZA  Windows  5
Run Code Online (Sandbox Code Playgroud)

相反,我想得到这个结果:

ZA  Others  4
ZA  Android 4
ZA  Mac     8
ZA  Windows 5
Run Code Online (Sandbox Code Playgroud)

我的下一次尝试是这个查询,但它并没有真正起作用:

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(agent);
Run Code Online (Sandbox Code Playgroud)

这是结果:

ZA  Others  4
ZA  OthersAOthersnOthersdOthersrOthersoOthersiOthersdOthers 4 …
Run Code Online (Sandbox Code Playgroud)

null hadoop hive replace

7
推荐指数
2
解决办法
4万
查看次数

标签 统计

hadoop ×1

hive ×1

null ×1

replace ×1