select
a.account,
count(rd.id) filter (
where rd.sum_dt_pu is not null
or rd.sum_ct_pu is not null
) as pu_rows,
count(rd.id) filter (
where rd.sum_dt_bu is not null
or rd.sum_ct_bu is not null
) as bu_rows,
coalesce(sum(
coalesce(rd.sum_dt_pu, 0)
- coalesce(rd.sum_ct_pu, 0)
), 0) as sum_pu,
coalesce(sum(
coalesce(rd.sum_dt_bu, 0)
- coalesce(rd.sum_ct_bu, 0)
), 0) as sum_bu
from (
values
('60301'),
('60302'),
('60322'),
('60323')
) as a(account)
left join back_office.report_conformity_pu_bu_detail rd
on rd.report_conformity_pu_bu_id = 97
and rd.account = a.account
group by a.account
order by a.accountA