declare @a table(a char(10),b int)
insert into @a select 'B',3
union all select 'A',2
union all select 'C',6
union all select 'B',4
select c=(select count(*) from (select distinct a from @a) a where b.a>=a.a ),a ,sum(B)AS B FROM @A b group by a
result:
c a B
----------- ---------- -----------
1 A 2
2 B 7
3 C 6