Query editor
withBase as (selectaddress,token_symbol as symbol,balance,balance_usd,token_addressfrom tokens_ethereum.balances_dailywhere address in (0x1ae6dcbc88d6f81a7bcfccc7198397d776f3592e, 0xb95a4779ccedc53010ef0df8bf8ed6aeb0e8c2b2, 0x8E4aD455225Dae1A78AB375FCb9eD9d94A4BE859) and day = date_trunc('day', now())and (token_standard = 'erc20' or token_standard = 'native')and balance_usd > 1order by balance_usd desc),APW as (Selectblock_date,sum(amount) over (order by block_date rows between unbounded preceding and current row) as totalfrom tokens_ethereum.transferswhere "from" = 0xb95a4779ccedc53010ef0df8bf8ed6aeb0e8c2b2and to = 0xC5ca1EBF6e912E49A6a70Bb0385Ea065061a4F09and contract_address = 0x4104b135DBC9609Fc1A9490E61369036497660c8order by block_date desc),APW_price AS (SELECT CASEWHEN token_bought_address = 0x4104b135dbc9609fc1a9490e61369036497660c8 THEN amount_usd / token_bought_amountELSE amount_usd / token_sold_amountEND AS price,CASEWHEN token_bought_address = 0x4104b135dbc9609fc1a9490e61369036497660c8 THEN token_bought_addressELSE token_sold_addressEND AS tokenAddress,block_dateFROM dex.tradesWHERE (token_bought_address = 0x4104b135dbc9609fc1a9490e61369036497660c8OR token_sold_address = 0x4104b135dbc9609fc1a9490e61369036497660c8)AND block_date > cast('2022-04-01 00:00' as timestamp)),veAPW as(selectAPW_price.block_date,total,avg(total * price) as veAPWfrom APW, APW_pricegroup by 1, 2order by APW_price.block_date desclimit 1),joigned as (selectaddress,symbol,balance,balance_usd,token_address