Query editor
-- Query 9: Average and Median Transaction Value by Bridge Protocol-- Section 3 (What Drives Choice) — proxy for user type (retail vs institutional)---- Approach:-- Calculate avg, median, and percentile stats per bridge.-- Median is more meaningful than avg since whale txs skew the mean heavily.-- Also includes p25 and p75 to show the spread.---- Known data issues:-- - Agglayer excluded (inflated volume)-- - LayerZero has near-zero amount_usd (pricing issue)---- Chart: Bar chart (median tx value by bridge), or grouped bar showing avg vs median-- FIX: tokens.erc20 contains duplicate rows per token (same contract_address + blockchain-- with slightly different metadata). Joining bridges_evms.flows directly against tokens.erc20-- causes a fan-out join, multiplying each bridge row by the number of duplicates and inflating-- COUNT(*), SUM(amount_usd), AVG(), and APPROX_PERCENTILE(). Deduplicating into a CTE first-- ensures a 1:1 join so each bridge transaction is counted exactly once.WITH stablecoin_tokens AS (SELECT DISTINCT contract_address, blockchainFROM tokens.erc20WHERE symbol IN ('USDC', 'USDC.e', 'USDbC', 'USDT', 'USDT0','DAI', 'BUSD', 'TUSD', 'FRAX', 'LUSD','USDP', 'PYUSD', 'GHO', 'USDe', 'USDS', 'crvUSD')),stablecoin_bridges AS (SELECTb.bridge_name,b.amount_usdFROM bridges_evms.flows bINNER JOIN stablecoin_tokens tON b.deposit_token_address = t.contract_addressAND b.deposit_chain = t.blockchainWHERE b.deposit_block_date >= CURRENT_DATE - INTERVAL '12' MONTHAND b.amount_usd > 0AND b.bridge_name != 'Agglayer'),top_bridges AS (SELECT bridge_nameFROM stablecoin_bridgesGROUP BY bridge_nameORDER BY SUM(amount_usd) DESCLIMIT 10)SELECTsb.bridge_name,COUNT(*) AS tx_count,SUM(sb.amount_usd) AS total_volume_usd,ROUND(AVG(sb.amount_usd), 2) AS avg_tx_usd,ROUND(APPROX_PERCENTILE(sb.amount_usd, 0.5), 2) AS median_tx_usd,ROUND(APPROX_PERCENTILE(sb.amount_usd, 0.25), 2) AS p25_tx_usd,ROUND(APPROX_PERCENTILE(sb.amount_usd, 0.75), 2) AS p75_tx_usd,-- avg/median ratio — higher means more whale-skewedROUND(AVG(sb.amount_usd) / NULLIF(APPROX_PERCENTILE(sb.amount_usd, 0.5), 0), 1) AS avg_median_ratio