Query editor
WITH base AS (SELECT *FROM "query_8187606(lookback_days='{{lookback_days}}')"),pair_rollup AS (SELECT pair_key,max(pair) AS pair,asset0_address,max(asset0_symbol) AS asset0_symbol,max(asset0_trust_class) AS asset0_trust_class,asset1_address,max(asset1_symbol) AS asset1_symbol,max(asset1_trust_class) AS asset1_trust_class,both_assets_trusted,array_join(array_sort(array_distinct(array_agg(concat('V', version)))), ', ')AS versions,sum(pool_count) AS pool_day_count,sum(swap_count) AS swap_count,sum(priced_swap_count) AS priced_swap_count,sum(volume_usd) AS volume_usd,sum(gross_swap_fees_usd_estimate) AS gross_swap_fees_usd_estimate,sum(generated_protocol_revenue_usd_estimate)AS generated_protocol_revenue_usd_estimate,sum(generated_protocol_revenue_asset0_estimate)AS generated_protocol_revenue_asset0_estimate,sum(generated_protocol_revenue_asset1_estimate)AS generated_protocol_revenue_asset1_estimateFROM baseGROUP BY 1, 3, 6, 9),scoped AS (SELECT 'At least one trusted asset' AS universe, *FROM pair_rollupUNION ALLSELECT 'Both assets trusted' AS universe, *FROM pair_rollupWHERE both_assets_trusted),ranked AS (SELECT *,row_number() OVER (PARTITION BY universeORDER BY generated_protocol_revenue_usd_estimate DESC NULLS LAST,pair_key) AS revenue_rank,generated_protocol_revenue_usd_estimate/ nullif(sum(generated_protocol_revenue_usd_estimate)OVER (PARTITION BY universe),0) AS revenue_shareFROM scopedWHERE coalesce(generated_protocol_revenue_usd_estimate, 0) > 0)SELECT universe,revenue_rank,concat(pair, ' · ', substr(pair_key, 3, 6)) AS pair_display,