Query editor
WITH reg AS (SELECT token_address FROM query_8223393),bstock_txs AS (SELECT DISTINCT d.block_date, d.tx_hashFROM dex.trades dWHERE d.blockchain = 'bnb'AND d.block_month >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '30' DAY)AND d.block_date >= CURRENT_DATE - INTERVAL '30' DAYAND d.block_date < CURRENT_DATEAND (d.token_bought_address IN (SELECT token_address FROM reg)OR d.token_sold_address IN (SELECT token_address FROM reg))),chain_daily AS (SELECT block_date,count(DISTINCT tx_hash) AS chain_transactions,sum(tx_fee) AS chain_fees_native,sum(tx_fee_usd) AS chain_fees_usdFROM gas.feesWHERE blockchain = 'bnb'AND block_month >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '30' DAY)AND block_date >= CURRENT_DATE - INTERVAL '30' DAYAND block_date < CURRENT_DATEGROUP BY 1),bstock_daily AS (SELECT b.block_date,count(DISTINCT b.tx_hash) AS bstock_dex_transactions,sum(g.tx_fee) AS bstock_fees_native,sum(g.tx_fee_usd) AS bstock_fees_usdFROM bstock_txs bLEFT JOIN gas.fees gON g.blockchain = 'bnb'AND g.block_month >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '30' DAY)AND g.block_date = b.block_dateAND g.tx_hash = b.tx_hashGROUP BY 1)SELECT block_date,bstock_dex_transactions,chain_transactions,100e0 * bstock_dex_transactions / NULLIF(chain_transactions, 0) AS transaction_share_pct,bstock_fees_native,bstock_fees_usd,chain_fees_native,chain_fees_usd,100e0 * bstock_fees_usd / NULLIF(chain_fees_usd, 0) AS fee_share_pct,bstock_fees_usd / NULLIF(bstock_dex_transactions, 0) AS fee_usd_per_bstock_txFROM bstock_dailyJOIN chain_daily USING (block_date)ORDER BY 1