Query editor
with table_details as(select block_date, date_trunc('hour',block_time) as time_hour, block_time, amount_usd as usd_amount, token_bought_amount as token_amountfrom dex.trades where blockchain = 'bnb' and token_bought_address = 0x23d3f4eaaa515403c6765bb623f287a8cca28f2band amount_usd is not nullunion allselect block_date, date_trunc('hour',block_time) as time_hour,block_time, amount_usd as usd_amount, token_sold_amount as token_amountfrom dex.trades where blockchain = 'bnb' and token_sold_address = 0x23d3f4eaaa515403c6765bb623f287a8cca28f2band amount_usd is not null),table_hour_1 as (select block_date, time_hour, block_time , row_number() OVER (PARTITION BY time_hour ORDER BY block_time DESC) AS rank , usd_amount, token_amount from table_details),table_hour_2 as (select block_date, time_hour, usd_amount / token_amount as price from table_hour_1 where rank = 1)select block_date, avg(price) * (1e9-815385163.5) as avg_market_cap from table_hour_2 group by block_date order by block_date desc