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
from operations o
join back_office.operation_type ot
on ot.id = o.operation_type_id
where o.deb_mnemonics like '%СВ%'
and coalesce(o.cred_mnemonics, '') not like '%НДФЛ%'
group by
o.id,
o.ef_year,
o.operation_type_id,
ot.code,
ot.name,
o.deb_mnemonics,
o.cred_mnemonics
order by o.ef_year, o.id;