Payments Table
CustomerPayment_typeAmountPeterCredit100PeterCredit300JohnCredit1000JohnDebit500
select customer,
sum(case when payment_type = 'credit' then amount else 0 end) as credit,
sum(case when payment_type = 'debit' then amount else 0 end) as debit
from payments
group by ...