Query editor
with all_trades as (selectblock_time,token_bought_mint_address as token_bought,token_sold_mint_address as token_sold,token_bought_amount,token_sold_amount,amount_usdfrom dex_solana.trades),trades_categorised as (selectdate_trunc('minute', block_time) as block_time_hour,case when token_bought in ('So11111111111111111111111111111111111111112','EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v') then 'sell' else 'buy' end as tx_category_flag,token_bought,token_sold,token_bought_amount,token_sold_amount,amount_usdfrom all_trades),volume as (selectblock_time_hour,tx_category_flag,casewhen tx_category_flag = 'buy' then token_boughtwhen tx_category_flag = 'sell' then token_soldelse nullend as token_transacted,sum(amount_usd) as total_usd_volumefrom trades_categorisedgroup by 1, 2, 3order by block_time_hour),directional_volume as (selectblock_time_hour,token_transacted,casewhen tx_category_flag = 'buy' then total_usd_volumeend as buying_volume,casewhen tx_category_flag = 'sell' then total_usd_volumeend as selling_volumefrom volume),total_volume as (selectblock_time_hour,token_transacted,buying_volume,selling_volume,(buying_volume + selling_volume) as total_volume,(buying_volume/(buying_volume + selling_volume)) as perc_buying_volume,