Query editor
with prices as (selectmax(case when symbol = 'BTC' then price end) as btc_usd,max(case when symbol = 'ADA' then price end) as ada_usd,max(case when symbol = 'ETH' then price end) as eth_usd,max(case when symbol = 'SOL' then price end) as sol_usd,max(case when symbol = 'BNB' then price end) as bnb_usd,max(case when symbol = 'TRX' then price end) as trx_usd,max(case when symbol = 'AVAX' then price end) as avax_usd,max(case when symbol = 'POL' then price end) as matic_usd,max(case when symbol = 'TON' then price end) as ton_usdfrom (select symbol, price,row_number() over (partition by symbol order by minute desc) as rnfrom prices.usdwhere symbol in ('BTC', 'ADA', 'ETH', 'SOL', 'BNB', 'TRX', 'AVAX', 'POL', 'TON')and minute >= now() - interval '1' hour)where rn = 1),bitcoin as (select block_date as day, 'Bitcoin' as chain,avg(fee) * (select btc_usd from prices) as avg_fee_usdfrom bitcoin.transactionswhere block_date >= casewhen cast('{{days}}' as varchar) = 'all-time' then date '2000-01-01'else current_date - interval '1' day * cast('{{days}}' as integer)endand is_coinbase = falsegroup by 1),cardano as (select date_trunc('day', block_time) as day, 'Cardano' as chain,avg(fee_lovelace) / 1e6 * (select ada_usd from prices) as avg_fee_usdfrom cardano.transactionwhere date_trunc('day', block_time) >= casewhen cast('{{days}}' as varchar) = 'all-time' then date '2000-01-01'else current_date - interval '1' day * cast('{{days}}' as integer)endgroup by 1),ethereum as (select block_date as day, 'Ethereum' as chain,avg(cast(gas_used as double) * cast(gas_price as double)) / 1e18 * (select eth_usd from prices) as avg_fee_usdfrom ethereum.transactionswhere block_date >= casewhen cast('{{days}}' as varchar) = 'all-time' then date '2000-01-01'else current_date - interval '1' day * cast('{{days}}' as integer)endgroup by 1),solana as (select block_date as day, 'Solana' as chain,avg(cast(fee as double)) / 1e9 * (select sol_usd from prices) as avg_fee_usdfrom solana.transactionswhere block_date >= casewhen cast('{{days}}' as varchar) = 'all-time' then date '2000-01-01'else current_date - interval '1' day * cast('{{days}}' as integer)endgroup by 1