Query editor
WITH base_weekly AS (SELECTDATE_TRUNC('week', block_time) AS week_start,COUNT(hash) AS base_tx_countFROM base.transactionsWHERE success = TRUEGROUP BY 1),aerodrome_weekly AS (SELECTDATE_TRUNC('week', block_date) AS week_start,COUNT(*) AS aerodrome_tx_countFROM dex.tradesWHERE project = 'aerodrome'GROUP BY 1),joined AS (SELECTb.week_start,b.base_tx_count,COALESCE(a.aerodrome_tx_count, 0) AS aerodrome_tx_count,COALESCE(CAST(a.aerodrome_tx_count AS DOUBLE) / b.base_tx_count, 0) * 100 AS tx_ratio_percentFROM base_weekly bLEFT JOIN aerodrome_weekly a ON b.week_start = a.week_startWHERE b.week_start < DATE_TRUNC('week', CURRENT_DATE))SELECTweek_start AS date,base_tx_count,aerodrome_tx_count,tx_ratio_percent,AVG(tx_ratio_percent) OVER (ORDER BY week_startROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS "6_week_ma_tx_ratio_percent"FROM joinedORDER BY week_start;