Query editor
with full_range as (select t.*, a.amount_typefrom unnest( SEQUENCE(date '2019-12-16', current_date, interval '1' day) ) as t(dt)cross join unnest(array[0.1, 1, 10, 100] ) as a (amount_type)order by t.dt, amount_type), daily_inflow as (select block_date, amount, sum(amount) as deposit_amountfrom tornado_cash.depositswhere blockchain = 'ethereum'and currency_symbol = 'ETH'group by block_date, amount), daily_outflow as (select block_date, amount, sum(amount) as withdraw_amountfrom tornado_cash.withdrawalswhere blockchain = 'ethereum'and currency_symbol = 'ETH'group by block_date, amount), net as (select coalesce(i.block_date, o.block_date) as block_date, coalesce(i.amount, o.amount) as amount_type, coalesce(i.deposit_amount,0) - coalesce(o.withdraw_amount, 0) as net_amountfrom daily_inflow i full join daily_outflow o on i.block_date = o.block_date and i.amount = o.amount), net_full_range as (select f.dt, f.amount_type, coalesce(n.net_amount, 0) as net_amountfrom full_range f left join net n on f.dt = n.block_date and f.amount_type = n.amount_type), balances as (select *, sum(net_amount) over(partition by amount_type order by dt rows unbounded preceding ) as pools_balancesfrom net_full_rangeorder by dt, amount_type)select * from balancesorder by dt, amount_type