Query editor
WITH base as (select * from dune.bulla.result_bulla_pool_metrics),-- Get the latest date for each pool to ensure we have the most recent datalatest_pool_data AS (SELECTcontract_address,MAX(time) as latest_timeFROMbaseGROUP BYcontract_address),-- Join the latest pool data with the full dataset to get all metricscurrent_pool_metrics AS (SELECTb.contract_address,b.pool_name,b.t0_symbol,b.t1_symbol,b.fee_pool_label,b.fee_tier_percent,b.tvl_usd,b.avg_7day_fee_tvl_ratio,b.avg_7day_volume_tvl_ratio,b.fees_earned_usdFROMbase bJOINlatest_pool_data lpdON b.contract_address = lpd.contract_addressAND b.time = lpd.latest_time),-- Rank pools by 7-day average fee/TVL ratioranked_pools AS (SELECT*,-- Add rank based on 7-day fee/TVL ratio (highest first)ROW_NUMBER() OVER (ORDER BY avg_7day_fee_tvl_ratio DESC) as fee_tvl_rankFROMcurrent_pool_metrics)-- Return the final ranked results with relevant columnsSELECTfee_tvl_rank as rank,pool_name,t0_symbol || '/' || t1_symbol as token_pair,fee_pool_label,avg_7day_fee_tvl_ratio as weekly_fee_tvl_ratio,avg_7day_volume_tvl_ratio as weekly_volume_tvl_ratio,tvl_usd,fees_earned_usdFROMranked_poolsORDER BYfee_tvl_rank ASC