select
count(*) as bu_rows,
count(*) filter (
where exists (
select 1
from prod_line.pens_scheme ps
where lower(btrim(cast(ps.uid_1c as text)))
= lower(btrim(rd.uidpensionscheme))
and nullif(btrim(rd.uidpensionscheme), '') is not null
)
) as rows_with_found_scheme,
count(*) filter (
where nullif(btrim(rd.uidsubtypeactivity), '') is not null
) as rows_with_strategy_uid,
count(*) filter (
where exists (
select 1
from prod_line.hb_invest_strategy st
where lower(btrim(cast(st.uid_1c as text)))
= lower(btrim(rd.uidsubtypeactivity))
and nullif(btrim(rd.uidsubtypeactivity), '') is not null
)
) as rows_with_found_strategy
from back_office.report_conformity_pu_bu_detail rd
where rd.report_conformity_pu_bu_id = 85
and (
rd.sum_dt_bu is not null
or rd.sum_ct_bu is not null
);