Query editor
with sums as (select block_date,casewhen token_pair is null and u.pair is not null then u.pairwhen token_pair is null and u.pair is null then 'OTHER'else token_pair end as pair,sum(amount_usd) as daily_pair_sumfrom xchange.trades t left join query_2971185 u on t.project_contract_address=u.addresswhere block_date >= CURRENT_DATE - INTERVAL '30' daygroup by block_date,casewhen token_pair is null and u.pair is not null then u.pairwhen token_pair is null and u.pair is null then 'OTHER'else token_pair end),raw as (selectcasewhen token_pair is null and u.pair is not null then u.pairwhen token_pair is null and u.pair is null then 'OTHER'else token_pair end as pair,t.*from xchange.trades t left join query_2971185 u on t.project_contract_address=u.addresswhere block_date >= CURRENT_DATE - INTERVAL '30' day),last24hr as (selectcasewhen token_pair is null and u.pair is not null then u.pairwhen token_pair is null and u.pair is null then 'OTHER'else token_pair end as pair,sum(t.amount_usd) as last_24hr_amtfrom xchange.trades t left join query_2971185 u on t.project_contract_address=u.addresswhere block_date >= CURRENT_DATE - INTERVAL '24' hourgroup bycasewhen token_pair is null and u.pair is not null then u.pairwhen token_pair is null and u.pair is null then 'OTHER'else token_pair end)select r.*, s.daily_pair_sum, tf.last_24hr_amtfrom sums s inner join raw r on s.pair=r.pair and s.block_date=r.block_dateleft join last24hr tf on r.pair=tf.pair