Not 100% sure what you are asking for.
But if you are trying to get sum of count for id where the right most number is the same, then here is a way of doing it in tsql.
with CntAll as (
select 1 id, 125 cnt
union select 2, 3
union select 3, 111
union select 32, 169
)
select
right(id, 1) rightid,
sum(cnt) SumCnt
from CntAll
group by
right(id, 1)
;
with CntAll as (
select 1 id, 125 cnt
union select 2, 3
union select 3, 111
union select 32, 169
), CntWithRightId as (
select
right(id, 1) rightId,
id,
cnt
from CntAll
)
select
rightid,
sum(cnt) SumCnt
from CntWithRightId
group by
rightid
;
Hope that helps you out.