with temp as (
select 1 as a,'A' as b,1 as c
union all
select 1 as a,'B' as b,2 as c
union all
select 1 as a,'C' as b,3 as c
union all
select 2 as a,'A' as b,4 as c
union all
select 2 as a,'B' as b,5 as c
union all
select 2 as a,'C' as b,6 as c
union all
select 3 as a,'A' as b,7 as c
union all
select 3 as a,'B' as b,8 as c
union all
select 3 as a,'C' as b,9 as c
)
select t1.a,t1.b,sum(t2.c) as sum
from temp t1 left join temp t2 on t1.b=t2.b and t1.a>=t2.a
group by t1.a,t1.b
order by b,a