Query editor
with tx as (select date_trunc('day', block_time) as day,try_cast(effective_gas_price as double) as effective_gas_price,try_cast(gas_used as double) as gas_used,try_cast(gas_used_for_l1 as double) as gas_used_for_l1 from robinhood.transactions),daily as (select day, count(*) as transactions,sum(gas_used) as total_gas_used,sum(gas_used_for_l1) as total_l1_gas,avg(effective_gas_price)/1e9 as avg_gas_price_gwei,sum(effective_gas_price*gas_used)/1e18 as total_fees_eth,sum(effective_gas_price*gas_used_for_l1)/1e18 as total_l1_fees_eth from tx group by 1),price as (select date_trunc('day', timestamp) as day,price as eth_price_usd from prices.day where symbol='ETH' and blockchain='ethereum' and contract_address=0x0000000000000000000000000000000000000000)selectd.day,d.transactions,d.total_gas_used,d.total_l1_gas,d.avg_gas_price_gwei,d.total_fees_eth,d.total_l1_fees_eth,d.total_fees_eth - d.total_l1_fees_eth as gross_profit_eth,p.eth_price_usd,d.total_fees_eth * p.eth_price_usd as total_fees_usd,d.total_l1_fees_eth * p.eth_price_usd as total_l1_fees_usd,(d.total_fees_eth - d.total_l1_fees_eth) * p.eth_price_usd as gross_profit_usd,(d.total_fees_eth * p.eth_price_usd) / nullif(d.transactions,0) as avg_fee_usd_per_tx,case when d.total_fees_eth <> 0 then (d.total_fees_eth - d.total_l1_fees_eth)/d.total_fees_eth else null end as gross_margin_pct from daily d left join price p on p.day = d.day order by d.day