当查询未返回所选列之一的任何结果时,我尝试显示默认值“其他”。我将向您展示这个例子。
此查询返回空值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);
Output:
ZA 4
ZA Android 4
ZA Mac 8
ZA Windows 5
相反,我想得到这个结果:
ZA Others 4
ZA Android 4
ZA Mac 8
ZA Windows 5
我的下一次尝试是这个查询,但它也没有真正起作用:
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);
这是结果:
ZA Others 4
ZA OthersAOthersnOthersdOthersrOthersoOthersiOthersdOthers 4
ZA OthersMOthersaOtherscOthers 8
ZA OthersWOthersiOthersnOthersdOthersoOtherswOtherssOthers 5