Det, du prøver at gøre, kaldes betinget aggregering. Du kan bruge
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 prøver at gøre, kaldes betinget aggregering. Du kan bruge
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