select
t1_0.client_id,
c2_0.name,
g1_0.type_code,
c1_0.generation_id,
sum(c1_0.balance)
from
Card c1_0
join
Generation g1_0
on g1_0.id=c1_0.generation_id
join
CardType t1_0
on t1_0.code=g1_0.type_code
join
Client c2_0
on c2_0.id=t1_0.client_id
group by
t1_0.client_id,
g1_0.type_code,
c1_0.generation_id
order by
c2_0.name,
g1_0.type_code,
c1_0.generation_id