Det du försöker göra kallas villkorlig aggregering. Du kan använda
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
Det du försöker göra kallas villkorlig aggregering. Du kan använda
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