0

How can I show output in % using this case condition in clickhouse db.

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

1 Answers1

0

But it works as is????

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 flavored syntax:

select ROUND(uniqExactIf(id,status = 'approved')/uniqExact(id2) * 100) as "SR- txns"
from test
┌─SR- txns─┐
│       30 │
└──────────┘
Denny Crane
  • 11,574
  • 2
  • 19
  • 30
  • Is it possible to check this question and help? Thank https://stackoverflow.com/q/75594142/8519380 – Sardar Mar 01 '23 at 05:24