Загрузка данных


select
    count(*) as bu_rows,

    count(*) filter (
        where nullif(btrim(rd.uidpensionscheme), '') is not null
    ) as rows_with_scheme_uid,

    count(*) filter (
        where exists (
            select 1
            from prod_line.pens_scheme ps
            where lower(
                nullif(btrim(cast(ps.uid_1c as text)), '')
            ) = lower(
                nullif(btrim(rd.uidpensionscheme), '')
            )
        )
    ) 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(
                nullif(btrim(cast(st.uid_1c as text)), '')
            ) = lower(
                nullif(btrim(rd.uidsubtypeactivity), '')
            )
        )
    ) as rows_with_found_strategy

from back_office.report_conformity_pu_bu_detail rd

where rd.report_conformity_pu_bu_id = 94
  and (
      rd.sum_dt_bu is not null
      or rd.sum_ct_bu is not null
  );