Query editor
WITH eth_price AS (SELECTdate_trunc('hour', minute) AS hour,AVG(price) as eth_priceFROM prices.usdWHEREsymbol = 'WETH'and blockchain = 'ethereum'and date_trunc('day', minute) < current_dateand date_trunc('day', minute) >= current_date - interval '{{Days}}' dayGROUP BY 1),temp as (SELECTdate_trunc('day', block_time) AS day,approx_percentile( (l1_fee/1e18 + ((gas_used/1e18) * gas_price)) * eth_price, 0.5) as dune_txcosts_usd-- approx_percentile( (l1_fee/1e18 + ((gas_used/1e18) * gas_price)), 0.5) as txcosts_median_eth,FROM optimism.transactions tLEFT JOIN eth_price e ON date_trunc('hour', t.block_time) = e.hourWHEREdate_trunc('day', block_time) < current_dateAND date_trunc('day', block_time) >= current_date - interval '{{Days}}' dayAND gas_price <> CAST(0 AS uint256)GROUP BY 1ORDER BY day DESC)SELECT t.*, gtp.value as gtp_txcosts_usdFROM temp tLEFT JOIN dune.web3_data.dataset_growthepie_20231219_2 gtp ON DATE(gtp.date) = DATE(t.day)WHERE gtp.metric_key = 'txcosts_median_usd'