首页  >  问答  >  正文

如何在 clickhouse 数据库中使用这种情况条件以 % 显示输出

如何在 clickhouse 数据库中使用这种情况条件以 % 形式显示输出。

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

P粉237125700P粉237125700401 天前680

全部回复(1)我来回复

  • P粉754473468

    P粉7544734682023-09-15 10:06:02

    但它按原样工作???

    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 │
    └──────────┘
    

    回复
    0
  • 取消回复