Query editor
-- AggregatorsWITH trades_with_bought_price AS (SELECTt.*,p1.price AS token_bought_priceFROMdex_aggregator.trades tLEFT JOINprices.usd p1 ON t.blockchain = p1.blockchainAND date_trunc('minute',t.block_time) = p1.minuteAND t.token_bought_address = p1.contract_addresswhere block_time > now() - interval '3' month),trades_with_both_prices AS (SELECTt.*,p2.price AS token_sold_priceFROMtrades_with_bought_price tLEFT JOINprices.usd p2 ON t.blockchain = p2.blockchainAND date_trunc('minute',t.block_time) = p2.minuteAND t.token_sold_address = p2.contract_addresswhere block_time > now() - interval '3' month),final_table as (SELECTblockchain,case when blockchain in ('base','optimism','arbitrum') then 'l2'when blockchain in ('ethereum') then 'mainnet'else 'else' end as blockchain_cat,block_time,project,version,(token_bought_amount * token_bought_price)/(token_sold_amount * token_sold_price) as trade_efficiency,token_bought_amount * token_bought_price AS token_bought_usd,token_sold_amount * token_sold_price AS token_sold_usd,token_bought_symbol,token_sold_symbol,case when amount_usd < 1000 then 1000when amount_usd < 10000 then 10000when amount_usd < 100000 then 100000when amount_usd >= 100000 then 200000 end as size_category,case when token_bought_symbol in ('USDC','DAI','USDT','FRAX') then 'stable'when token_bought_symbol in ('ETH','WETH','WBTC') then 'big'else 'alt'end as token_bought_cat,case when token_sold_symbol in ('USDC','DAI','USDT','FRAX') then 'stable'when token_sold_symbol in ('ETH','WETH','WBTC') then 'big'else 'alt' end as token_sold_catFROMtrades_with_both_prices),final as (select *, concat(token_bought_cat, '-', token_sold_cat) as route,case when token_sold_cat = 'stable' and token_bought_cat = 'stable' then 'stable'when token_sold_cat in ('stable', 'big') and token_bought_cat in ('stable', 'big') then 'big'when token_sold_cat = 'alt' or token_bought_cat = 'alt' then 'alt'else 'alt' end as route_cat