Query editor
WITH all_activity AS (SELECTblock_time,depositor AS user,amount_usd,'supply' AS action_typeFROM aave_ethereum.supplyWHEREproject = 'aave'UNION ALLSELECTblock_time,borrower AS user,amount_usd,'borrow' AS action_typeFROM aave_ethereum.borrowWHEREproject = 'aave'), daily_metrics AS (SELECTDATE_TRUNC('day', block_time) AS day,COUNT(DISTINCT user) AS daily_active_users,COUNT(*) AS transaction_count,SUM(amount_usd) AS transaction_volumeFROM all_activityGROUP BY1), weekly_metrics AS (SELECTDATE_TRUNC('week', block_time) AS week,COUNT(DISTINCT user) AS weekly_active_usersFROM all_activityGROUP BY1), monthly_metrics AS (SELECTDATE_TRUNC('month', block_time) AS month,COUNT(DISTINCT user) AS monthly_active_usersFROM all_activityGROUP BY1), growth_metrics AS (SELECTday,daily_active_users,AVG(daily_active_users) OVER (ORDER BY day ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS users_7d_avg,AVG(daily_active_users) OVER (ORDER BY day ROWS BETWEEN 29 PRECEDING AND CURRENT ROW) AS users_30d_avg,AVG(daily_active_users) OVER (ORDER BY day ROWS BETWEEN 89 PRECEDING AND CURRENT ROW) AS users_90d_avg,(daily_active_users - LAG(daily_active_users, 1) OVER (ORDER BY day)) / NULLIF(LAG(daily_active_users, 1) OVER (ORDER BY day), 0) AS daily_growth_rate,(daily_active_users - LAG(daily_active_users, 7) OVER (ORDER BY day)) / NULLIF(LAG(daily_active_users, 7) OVER (ORDER BY day), 0) AS weekly_growth_rate,(daily_active_users - LAG(daily_active_users, 30) OVER (ORDER BY day)) / NULLIF(LAG(daily_active_users, 30) OVER (ORDER BY day), 0) AS monthly_growth_rate,transaction_count,transaction_volume,AVG(transaction_volume) OVER (ORDER BY day ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS volume_7d_avg,