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


with movements as (
    select
        t.id,
        t.operation_id,
        t.effective_date,
        t.value
    from back_office.account a
    join back_office.transaction t
        on t.credit_account_id = a.id
    where a.owner_sharer_id = 14280816
        and t.effective_date >= cast('2026-08-01' as date)
        and t.effective_date < cast('2026-10-01' as date)

    union

    select
        t.id,
        t.operation_id,
        t.effective_date,
        t.value
    from back_office.account a
    join back_office.transaction t
        on t.debit_account_id = a.id
    where a.owner_sharer_id = 14280816
        and t.effective_date >= cast('2026-08-01' as date)
        and t.effective_date < cast('2026-10-01' as date)
)
select
    m.effective_date,
    ot.code as operation_code,
    count(*) as transaction_count,
    sum(m.value) as total_value
from movements m
join back_office.operation o
    on o.id = m.operation_id
join back_office.operation_type ot
    on ot.id = o.operation_type_id
group by m.effective_date, ot.code
order by m.effective_date, ot.code;