Query editor
-- the number's off!WITH PriceChanges AS (SELECTevt_block_date,newPrice / 1e8 AS usdPrice, -- Convert to USDLEAD(evt_block_date, 1) OVER (ORDER BY evt_block_date) AS next_change_dateFROMfarcaster_optimism.StorageRegistry_evt_SetPrice),RentWithPrices AS (SELECTr.evt_block_date,r.units,COALESCE(pc.usdPrice, (SELECT MAX(usdPrice)FROM PriceChangesWHERE evt_block_date <= r.evt_block_date)) AS usdPrice -- Use COALESCE to handle NULLsFROMfarcaster_optimism.StorageRegistry_evt_Rent rLEFT JOIN PriceChanges pc ON r.evt_block_date >= pc.evt_block_dateAND (r.evt_block_date < pc.next_change_date OR pc.next_change_date IS NULL)),DailyRevenue AS (SELECTevt_block_date,SUM(units * usdPrice) AS daily_usd_revenueFROMRentWithPricesWHEREevt_block_date NOT IN (CAST('2023-08-29' AS DATE))GROUP BYevt_block_date)SELECTCAST(evt_block_date AS TIMESTAMP) AS evt_block_date,daily_usd_revenue,SUM(daily_usd_revenue) OVER (ORDER BY evt_block_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_revenueFROMDailyRevenueORDER BYevt_block_date DESC;