mysql 如何在clickhouse数据库中使用此case条件以%显示输出

omhiaaxx  于 2023-02-21  发布在  Mysql
关注(0)|答案(1)|浏览(175)

如何在clickhouse数据库中使用此case条件以%显示输出。

ROUND(count(distinct case when bt.status = 'approved' then bt.id else null end)/count(distinct p.id) * 100) as "SR- txns"
yizd12fk

yizd12fk1#

但它的工作原理是????

create table test(id int, id2 int, status String) Engine=Memory
as select number,number, ['approved', 'completed'][number%3] from numbers(10);

select ROUND(count(distinct case when status = 'approved' then id else null end)/count(distinct id2) * 100) as "SR- txns"
from test
┌─SR- txns─┐
│       30 │
└──────────┘

Clickhouse风格的语法:

select ROUND(uniqExactIf(id,status = 'approved')/uniqExact(id2) * 100) as "SR- txns"
from test
┌─SR- txns─┐
│       30 │
└──────────┘

相关问题