Query editor
WITH flows AS (SELECTblockchain,block_date,tx_hash,ABS(amount_usd) AS volume_usd,CASEWHEN "to" = 0x1f8E735f424B7A49A885571A2fA104E8C13C26c7 THEN "from"ELSE "to"END AS user_addressFROM tokens.transfersWHERE( "to" = 0x1f8E735f424B7A49A885571A2fA104E8C13C26c7OR "from" = 0x1f8E735f424B7A49A885571A2fA104E8C13C26c7 )AND "from" NOT IN (0x3c2269811836af69497e5f486a85d7316753cf62,0xb6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7,0x66a71dcef29a0ffbdbe3c6a460a3b5bc225cd675,0x4200000000000000000000000000000000000006,0x0000000000000000000000000000000000000000,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0x82af49447d8a07e3bd95bd0d56f35241523fbab1)AND "to" NOT IN (0x3c2269811836af69497e5f486a85d7316753cf62,0xb6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7,0x66a71dcef29a0ffbdbe3c6a460a3b5bc225cd675,0x4200000000000000000000000000000000000006,0x0000000000000000000000000000000000000000,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0x82af49447d8a07e3bd95bd0d56f35241523fbab1)AND blockchain IN ('optimism','ethereum','bnb','base','avalanche_c','arbitrum')),user_stats AS (SELECTblockchain,user_address,SUM(volume_usd) AS user_total_volume_usd,COUNT(DISTINCT tx_hash) AS user_tx_countFROM flowsGROUP BY blockchain, user_address)SELECTCOUNT(*) AS user_count,SUM(user_total_volume_usd) AS total_volume_usd,AVG(user_total_volume_usd) AS avg_volume_per_user_usd,approx_percentile(user_total_volume_usd, 0.5)AS median_volume_per_user_usd,AVG(user_tx_count) AS avg_tx_per_user,approx_percentile(user_tx_count, 0.5) AS median_tx_per_user,-- total distinct txs across all chains(SELECT COUNT(DISTINCT tx_hash) FROM flows) AS total_tx_countFROM user_stats;