Query editor
with-- Базовые данные адресов Binancebinance_addresses as (selectaddress,entity,distinct_name,track_inflow,track_outflow,inverse_valuesfrom query_3797772where entity = 'Binance'),-- Единый запрос для балансов с временными меткамиbtc_balances_with_history as (selectentity,distinct_name,block_date,sum(daily_net_flow) over (partition by entity, distinct_name order by block_date) as running_balancefrom (selectb.entity,b.distinct_name,cast(i.block_time as date) as block_date,sum(case-- Притоки (outputs)when i.type = 'output' and b.track_inflow = true thencase when b.inverse_values = true then -i.value else i.value end-- Оттоки (inputs)when i.type = 'input' and b.track_outflow = true then-1 * case when b.inverse_values = true then -i.value else i.value endelse 0end) as daily_net_flowfrom (-- Outputs (притоки)selecto.address,o.block_time,o.value,'output' as typefrom bitcoin.outputs owhere o.value > 0and o.block_time > date(try_cast('2019-07-24' as timestamp))union all-- Inputs (оттоки)selecti.address,i.block_time,i.value,'input' as typefrom bitcoin.inputs iwhere i.value > 0and i.block_time > date(try_cast('2019-07-24' as timestamp))) i