将使用 clickhouse 进行带有条件计数的 Postgres 查询转换
时间:2024-02-08
浏览:325
作者:佚名
在Golang实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《将使用 clickhouse 进行带有条件计数的 Postgres 查询转换》,聊聊,希望可以帮助到正在努力赚钱的你。
问题内容
我需要将此 postgres 查询转换为 clickhouse:
select count(1) 过滤器(其中 car_model = 'chevrolet')、count(distinct car_num) 过滤器(其中 car_model='chevrolet');
我尝试过使用 countIf,但它不接受该条件。所以我需要一个选择。
正确答案
不接受条件是什么意思?
它按预期工作:
create table cars
(
`car_model` string,
`car_num` integer
)
engine = mergetree
order by tuple();
insert into cars values ('chevrolet', 1), ('chevrolet', 1), ('opel', 2), ('chevrolet', 3), ('dodge', 4), ('subaru', 16);
查询:
select
countif(1, car_model = 'chevrolet'),
countifdistinct(car_num, car_model = 'chevrolet')
from cars
结果:
Row 1: ────── countIf(1, equals(car_model, 'chevrolet')): 3 uniqExactIf(car_num, equals(car_model, 'chevrolet')): 2 1 row in set. Elapsed: 0.024 sec.
终于介绍完啦!小伙伴们,这篇关于《将使用 clickhouse 进行带有条件计数的 Postgres 查询转换》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.30
11.30
11.30
11.30
11.30
11.30
11.30
热门专题
