Clickhouse:0用于缺席汇总
想象一下有一个表:
code | value
------------
AAAA | 10
AAAA | 15
BBBB | 5
我想按代码计数(汇总),而缺乏代码计数为0:
select code, count(*) count
from table
where code in ('AAAA', 'CCCC')
group by code
上述查询的实际结果:
code | count
------------
AAAA | 2
但是我希望结果是:
code | count
------------
AAAA | 2
CCCC | 0
是否可以归档预期结果?如果是的话?
Imagine there is a table:
code | value
------------
AAAA | 10
AAAA | 15
BBBB | 5
I would like to count (aggregate) by code and for absent codes counted value to 0:
select code, count(*) count
from table
where code in ('AAAA', 'CCCC')
group by code
The actual result for query above:
code | count
------------
AAAA | 2
But I'd expect result to be:
code | count
------------
AAAA | 2
CCCC | 0
Is it possible to archive expected result? If yes how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做这样的事情:
请按照此操作 sql fiddel 。
You can do something like this:
Follow this SQL fiddel.