Query editor
WITHcalendar AS (WITH day_seq AS (SELECT (sequence(cast('2022-09-10' as date), cast(now() as date), interval '1' day)) day)SELECT days.dayFROM day_seqCROSS JOIN unnest(day) AS days(day)),shares AS (SELECTpreTotalEther*1e27/preTotalShares as pre_share_rate,postTotalEther*1e27/postTotalShares as post_share_rate,*FROM lido_ethereum.steth_evt_TokenRebased),oracles_data AS (--legacy oracleSELECT"evt_block_time" AS time,CAST(("postTotalPooledEther" - "preTotalPooledEther") * 365 * 24 * 60 * 60 / ("preTotalPooledEther") AS double) / timeElapsed * 100 AS protocol_apr,CAST(("postTotalPooledEther" - "preTotalPooledEther") * 365 * 24 * 60 * 60 / ("preTotalPooledEther") AS double) / timeElapsed * 0.9 * 100 AS "Lido staking APR(instant)","postTotalPooledEther","preTotalPooledEther"FROM lido_ethereum.LegacyOracle_evt_PostTotalSharesWHERE "evt_block_time" >= cast('2022-09-01 00:00' as timestamp)AND "evt_block_time" <= cast('2023-05-16 00:00' as timestamp)--new V2 oracleUNION ALLSELECTevt_block_time,(365 * 24 * 60 * 60 * (post_share_rate - pre_share_rate) / pre_share_rate / timeElapsed * 100) / 0.9 as protocol_apr,365 * 24 * 60 * 60 * (post_share_rate - pre_share_rate) / pre_share_rate / timeElapsed * 100 as "Lido staking APR(instant)",preTotalEther,postTotalEtherFROM shares)SELECT--o.*,o.time,avg(o."Lido staking APR(instant)") over (order by o.time rows between 6 preceding and current row) as "Lido staking APR(ma_7)"FROM oracles_data oORDER BY 1 DESCLIMIT 1 -- Return only the latest 7-day average APR