Query editor
with Exchange as (select distinct address,exchangefrom query_2613158WHERE EXCHANGE = 'Binance'union allselect '3AtnehKDkFPC1bKvdrEVPSRGCtxQH8F1R8' as address, 'Binance' as Exchange union allselect '3CySuFKbBS29M7rE5iJakZRNqb3msMeFoN' as address, 'Binance' as Exchange union allselect '3CySuFKbBS29M7rE5iJakZRNqb3msMeFoN' as address, 'Binance' as Exchange union allselect '34GUzCVLbdkMQ2UdVTaA4nxPwoovVS7y2J' as address, 'Binance' as Exchange union allselect '3NjHh71XgjikBoTNYdWgXiNeZcLaKNThgb' as address, 'Binance' as Exchange union allselect '3NXCvmLGz9SxYi6TnjbBQfQMcwiZ1iQETa' as address, 'Binance' as Exchange union allselect '3Me9QACjioepv2L2oKTC9QQ87NH6vFe1Zj' as address, 'Binance' as Exchange union allselect '3EVVc8e2rxwUuERtdJCduWig8DnpsUqyA6' as address, 'Binance' as Exchange union allselect '3EVVc8e2rxwUuERtdJCduWig8DnpsUqyA6' as address, 'Binance' as Exchange union allselect '3FrmCRcGKiTATfreBDM9F17yAUDoDsnWeA' as address, 'Binance' as Exchange union allselect '3EbJfpmFgufYtzW9UFvf1GAfm2ted1Rwnr' as address, 'Binance' as Exchange union allselect '3LYJfcfHPXYJreMsASk2jkn69LWEYKzexb' as address, 'Binance' as Exchange union allselect '1BAuq7Vho2CEkVkUxbfU26LhwQjbCmWQkD' as address, 'Binance' as Exchange union allselect '1PJiGp2yDLvUgqeBsuZVCBADArNsk6XEiw' as address, 'Binance' as Exchange),bin_outflow as (select date_trunc('day', a.block_time) as Day,b.exchange,sum(a.value)*-1 as Amountfrom bitcoin.inputs ainner join exchange bon a.address = b.addressand a.block_time >= date('2020-01-01')group by 1,2order by 1,2),bin_inflow as (select date_trunc('day', a.block_time) as Day,b.exchange,sum(a.value) as Amountfrom bitcoin.outputs ainner join exchange bon a.address = b.addressand a.block_time >= date('2020-01-01')group by 1,2order by 1,2),days as (select cast(day as timestamp) as day,'Binance' as exchange fromunnest(sequence(date('2020-01-01'), date(now()), interval '1' day)) AS t(day)),net_flow as (select a.day,a.exchange,coalesce(b.amount,0) as inflow,coalesce(c.amount,0) as outflowfrom days aleft join bin_inflow bon a.day = b.dayand a.exchange = b.exchangeleft join bin_outflow con a.day = c.dayand a.exchange = b.exchangeorder by a.day, a.exchange),