Query editor
with gas as (selectcase when '{{Timeframe}}' = 'Daily' then date_trunc('day', block_time)when '{{Timeframe}}' = 'Weekly' then date_trunc('week', block_time)when '{{Timeframe}}' = 'Monthly' then date_trunc('month', block_time) end as day,"from" as address,sum(gas_used / power(10, 18) * effective_gas_price) as gas_used_eth,count(distinct hash) as tx_count-- gas_used / power(10, 18) * effective_gas_price as avg_gas_used_ethfrom arbitrum.transactions tgroup by 1, 2),buckets as (selectday,-- gas_used_eth,approx_percentile(tx_count, 0.2) as p80,approx_percentile(tx_count, 0.4) as p60,approx_percentile(tx_count, 0.5) as p50,approx_percentile(tx_count, 0.6) as p40,approx_percentile(tx_count, 0.8) as p20,approx_percentile(tx_count, 0.9) as p10,approx_percentile(tx_count, 0.95) as p05,approx_percentile(tx_count, 0.99) as p01,approx_percentile(tx_count, 0.999) as p001from gasgroup by 1)selectgas.day,p80,p60p50,p40,p20,p10,p05,p01,p001,count(case when tx_count <= p10 then address end) as p10_address_count,-- count(case when tx_count > p20 and tx_count <= p10 then address end) as p10_address_count,-- count(case when tx_count > p10 and tx_count <= p05 then address end) as p05_address_count,count(case when tx_count > p10 and tx_count <= p001 then address end) as p001_address_count,-- count(case when tx_count > p01 and tx_count <= p001 then address end) as p001_address_count,count(case when tx_count > p001 then address end) as p000_address_count,sum(case when tx_count <= p10 then gas_used_eth else 0 end) as p10_gas_used_eth,-- sum(case when tx_count > p20 and tx_count <= p10 then gas_used_eth else 0 end) as p10_gas_used_eth,-- sum(case when tx_count > p10 and tx_count <= p05 then gas_used_eth else 0 end) as p05_gas_used_eth,sum(case when tx_count > p10 and tx_count <= p001 then gas_used_eth else 0 end) as p001_gas_used_eth,-- sum(case when tx_count > p01 and tx_count <= p001 then gas_used_eth else 0 end) as p001_gas_used_eth,sum(case when tx_count > p001 then gas_used_eth else 0 end) as p000_gas_used_eth,sum(case when tx_count <= p10 then tx_count else 0 end) as p10_tx_count,-- sum(case when tx_count > p20 and tx_count <= p10 then tx_count else 0 end) as p10_tx_count,-- sum(case when tx_count > p10 and tx_count <= p05 then tx_count else 0 end) as p05_tx_count,sum(case when tx_count > p10 and tx_count <= p001 then tx_count else 0 end) as p001_tx_count,-- sum(case when tx_count > p01 and tx_count <= p001 then tx_count else 0 end) as p001_tx_count,sum(case when tx_count > p001 then tx_count else 0 end) as p000_tx_count,count(address) as address_count,sum(gas_used_eth) as gas_used_ethfrom gasleft join bucketson gas.day = buckets.day