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