Query editor
WITH chain_activity AS (SELECT DISTINCT "from" AS wallet, DATE_TRUNC('month', block_time) AS active_month, 'Ethereum' AS chainFROM ethereum.transactionsUNION ALLSELECT DISTINCT "from", DATE_TRUNC('month', block_time), 'BNB'FROM bnb.transactionsUNION ALLSELECT DISTINCT "from", DATE_TRUNC('month', block_time), 'AVAX'FROM avalanche_c.transactionsUNION ALLSELECT DISTINCT "from", DATE_TRUNC('month', block_time), 'FTM'FROM fantom.transactions),user_migration AS (SELECTa.wallet,a.chain AS previous_chain,b.chain AS new_chain,a.active_month AS previous_month,b.active_month AS new_monthFROM chain_activity aJOIN chain_activity b ON a.wallet = b.walletAND a.chain <> b.chainAND a.active_month = b.active_month - INTERVAL '1' MONTH)SELECTprevious_chain,new_chain,COUNT(DISTINCT wallet) AS migrating_users,ROUND(COUNT(DISTINCT wallet) * 100.0 /NULLIF((SELECT COUNT(DISTINCT wallet) FROM chain_activity WHERE active_month = user_migration.previous_month), 0), 2)AS migration_rateFROM user_migrationGROUP BY previous_chain, new_chain, previous_monthORDER BY migrating_users DESC;