Query editor
withminute_price as (select date_trunc('minute', block_time) as block_time, sum(amount_usd) / sum(token_amount) as pricefrom (selectblock_time, amount_usd, casewhen token_bought_address = 0xba25b2281214300e4e649fead9a6d6acd25f1c0a then token_bought_amount_rawelse token_sold_amount_rawend as token_amount_raw, casewhen token_bought_address = 0xba25b2281214300e4e649fead9a6d6acd25f1c0a then token_bought_amountelse token_sold_amountend as token_amount-- , evt_indexfrom dex.tradeswhere(token_bought_address = 0xba25b2281214300e4e649fead9a6d6acd25f1c0aor token_sold_address = 0xba25b2281214300e4e649fead9a6d6acd25f1c0a)and blockchain = 'ethereum')where block_time > timestamp '2023-12-08 14:01'group by 1),rev as (select block_time, sum(value) as value from (selectdate_trunc('minute', evt_block_time) as block_time,sum(value) / pow(10, 18) as valuefrom erc20_ethereum.evt_Transferwhereto = 0xa0fCF4249fa6b8ea2be8285FF429EBD276adD2dBand contract_address = 0xba25b2281214300e4e649fead9a6d6acd25f1c0aand evt_block_number > 18743199and evt_tx_hash <> 0xcbfb82c73bc50248d3d208577b4094a55de3d9e824f138d482c14663a5019864group by 1union allSELECT date_col, 0FROMUNNEST(sequence(date '2023-12-09', current_date, INTERVAL '1' DAY)) t (date_col))group by 1),rev_with_price as (select date_trunc('day', block_time) as block_time, sum(value) as amount, sum(value * price) as usd_value, avg(day_close_price) as day_close_price from (selectr.block_time, nullif(r.value, 0) as value, p.price, row_number() over (partition by r.block_time order by p.block_time desc) as ranking, last_value(price) over (partition by date_trunc('day', r.block_time) order by p.block_time desc) as day_close_price-- , row_number() over (partition by date_trunc('day', r.block_time) order by p.block_time desc) as ranking_day