I have tried to get data through below query.
select substr(accid,1,3), sum(openbal)
from coacc
group by substr(accid,1,3)
union
select substr(accid,1,7), sum(openbal)
from coacc
group by substr(accid,1,7)
union
select substr(accid,1,12), sum(openbal)
from coacc
group by...