drop table lanagocreate table lana (a tinyint, b tinyint, c bit)insert lanaselect 1,1,0union all select 1,2,0union all select 1,2,0union all select 1,5,1union all select 2,1,1union all select 2,1,0union all select 2,3,1union all select 3,5,0union all select 3,4,0goselect a as value, count(*) as [count], convert(numeric,(select count(*) from lana where a = l.a and c = 1)) / convert(numeric,count(*)) as ratiofrom lana lgroup by ago
<O>