O que você está tentando fazer se chama agregação condicional. Você pode usar
select cname, sum(case when type='A' then amount else 0 end) as total_A, sum(case when type='B' then amount else 0 end) as total_B from balances group by cname O que você está tentando fazer se chama agregação condicional. Você pode usar
select cname, sum(case when type='A' then amount else 0 end) as total_A, sum(case when type='B' then amount else 0 end) as total_B from balances group by cname