Query editor
WITH users_current_week AS (SELECTDATE_TRUNC('week', block_date) AS week,account,COUNT(DISTINCT account) AS total_usersFROM ton.transactionsWHERE block_date >= date_trunc('day', NOW() - interval '1' year)and 1 = 1AND block_date < DATE_TRUNC('day', (SELECT MAX(block_date) FROM ton.transactions))GROUP BY 1, 2),users_last_week AS (SELECTDATE_TRUNC('week', block_date + INTERVAL '7' day) AS week,account,COUNT(DISTINCT account) AS total_usersFROM ton.transactionsWHERE block_date >= date_trunc('day', NOW() - interval '1' year)and 1 = 1AND block_date < DATE_TRUNC('week', (SELECT MAX(block_date) FROM ton.transactions))GROUP BY 1, 2)SELECTA.week,try_cast(COUNT(DISTINCT B.account) as decimal(18,2)) / try_cast(COUNT(DISTINCT A.account) as decimal (18,2)) as Retention_Rate_7_Days,COUNT(DISTINCT A.account) AS Weekly_Active_Users,COUNT(DISTINCT B.account) AS Users_Retained_over_one_weekFROM users_current_week AS ALEFT JOIN users_last_week AS B ON A.week = B.week AND A.account = B.accountGROUP BY 1order by 1 DESC