AS
select account_number as account_number
, coalesce(sum(amount) filter ( where status = 'PAID'), 0) as paid
, coalesce(sum(amount) filter ( where status = 'UNPAID'), 0) as unpaid
from temp.payments
group by account_number;

