Query editor
with disperse_ferc as(select-- cast(value as decimal(38,0))/1e18evt_tx_hashfromerc20_ethereum.evt_Transferwhereevt_block_time > TIMESTAMP '2023-05-31'and contract_address = 0x2ecba91da63c29ea80fbe7b52632ca2d1f8e5be0and ("from" = 0x6695f50eada6069c8494d65654e52f4c8e43b0bfand to = 0xd152f549545093347a162dce210e7293f1452150)),sub_address_list as(selectto as address,sum(cast(value as decimal(38,0)))/1e18 as receive_balancefromerc20_ethereum.evt_Transferwhereevt_block_time > TIMESTAMP '2023-05-31'and contract_address = 0x2ecba91da63c29ea80fbe7b52632ca2d1f8e5be0and evt_tx_hash in (select evt_tx_hash from disperse_ferc)and "from" = 0xd152f549545093347a162dce210e7293f1452150group by to)selectt2.address,t2.receive_balance,sum(if(t1."from" = t2.address,-cast(value as decimal(38,0)),cast(value as decimal(38,0)) ))/1e18 as holding_balance,cast((sum(if(t1."from" = t2.address,-cast(value as decimal(38,0)),cast(value as decimal(38,0)) ))/1e18 - t2.receive_balance) as double)/t2.receive_balance as change,max(if("from" = t2.address,evt_block_time + interval '8' hour,null)) as latest_sold_timefrom erc20_ethereum.evt_Transfer t1 inner join sub_address_list t2 on t1."from"=t2.address or t1.to=t2.addresswhere evt_block_time > TIMESTAMP '2023-05-31'and contract_address = 0x2ecba91da63c29ea80fbe7b52632ca2d1f8e5be0group by t2.address,t2.receive_balanceorder by latest_sold_time desc