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


select
    o.id as operation_id,
    o.ef_year,
    o.operation_type_id,
    ot.code,
    ot.name,
    o.deb_mnemonics,
    o.cred_mnemonics,
    count(*) as row_count,
    sum(o.value) as sum_value,
    case
        when o.deb_mnemonics is not null
         and o.deb_mnemonics not like '%СВ%'
         and o.deb_mnemonics not like '%ПП%'
         and ot.name not like '%Выплата%'
         and coalesce(o.cred_mnemonics, '') not like '%НДФЛ%'
        then 'Да'
        else 'Нет'
    end as passes_current_filter
from operations o
join back_office.operation_type ot
    on ot.id = o.operation_type_id
where o.operation_type_id in (
    112, -- Единовременная выплата
    118, -- НДФЛ с единовременной выплаты
    125, -- Возврат единовременной выплаты
    130, -- Возврат НДФЛ с единовременной выплаты
    173  -- Дополнительная единовременная выплата
)
group by
    o.id,
    o.ef_year,
    o.operation_type_id,
    ot.code,
    ot.name,
    o.deb_mnemonics,
    o.cred_mnemonics
order by
    o.id,
    o.deb_mnemonics,
    o.cred_mnemonics;