Query editor
with table_1 as (select a.*,erc20_ethereum.evt_Transfer.*FROM erc20_ethereum.evt_Transferinner join (select address,cex_name from cex.addresses where blockchain = 'ethereum' ) a on a.address = erc20_ethereum.evt_Transfer."from"where contract_address = 0x582d872a1b094fc48f5de31d3b73f2d9be47def1and "to" not in (select address from cex.addresses where blockchain = 'ethereum')),table_2 as (select day,symbol,price,decimalsfrom (select date_trunc('week',minute) day,symbol,price,decimals,row_number() over(partition by date_trunc('week',minute),symbol order by minute desc ) latest_day_pricefrom prices.usd where blockchain = 'ethereum' and symbol in ('TONCOIN')) awhere latest_day_price = 1 and day >=CAST('2021-08-22'as timestamp)),table_cex as (select table_2.day,value/pow(10,decimals) amount,value/pow(10,decimals)*price amount_usd,"from","to",cex_namefrom table_1left join table_2 on date_trunc('week',evt_block_time) = table_2.day),table_cex_transfers as (selectcex_name,day,sum(amount_usd) amount_usd,sum(sum(amount_usd)) over(partition by cex_name order by day) cum_amount_usd,sum(sum(amount_usd)) over(order by day) cum_amount_usd_totalfrom table_cexgroup by 1,2)select day,'total',sum(sum(amount_usd)) over(order by day) totalfrom table_cex_transfersgroup by 1,2order by day desclimit 1;