Query editor
WITH all_actions AS (SELECTdepositor as wallet,COUNT(*) as action_countFROM aave.supplyWHERE blockchain = 'ethereum'AND depositor IS NOT NULLGROUP BY depositorUNION ALLSELECTborrower as wallet,COUNT(*) as action_countFROM aave.borrowWHERE blockchain = 'ethereum'AND borrower IS NOT NULLGROUP BY borrower),wallet_totals AS (SELECTwallet,SUM(action_count) as total_actionsFROM all_actionsGROUP BY wallet),wallet_ranks AS (SELECTwallet,total_actions,NTILE(2) OVER (ORDER BY total_actions DESC) as wallet_percentileFROM wallet_totals),summary AS (SELECTwallet_percentile,SUM(total_actions) as actions_in_groupFROM wallet_ranksGROUP BY wallet_percentile)SELECTROUND(100.0 * MAX(CASE WHEN wallet_percentile = 2 THEN actions_in_group ELSE 0 END) / SUM(actions_in_group), 2) as bottom_50_pct_shareFROM summary