add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table customers (
customerid int,
supplierid int
)
select x.customerid, c.customerid,
(count(*) / num_x) as ratio
from customers c cross join
(select @X as customerid, count(*) as num_x
from customers c
where c.customerid = @X
) x
where exists (select 1
from customers cx
where cx.supplierid = c.supplierid and
cx.customerid = @X
)
group by c.customerid, x.num_x
having count(*) / x.num_x >= 0.8
order by ratio desc;