Query editor
WITH wallet_actions AS (SELECTtrader_id,COUNT(*) as action_countFROM dex_solana.tradesWHERE project = 'raydium'AND block_time >= CURRENT_DATE - INTERVAL '30' dayGROUP BY trader_id),wallet_ranks AS (SELECTtrader_id,action_count,SUM(action_count) OVER () as total_actions,SUM(action_count) OVER (ORDER BY action_count DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as cumulative_actions,COUNT(*) OVER () as total_walletsFROM wallet_actions),wallet_percentiles AS (SELECTtrader_id,action_count,total_actions,cumulative_actions,total_wallets,ROW_NUMBER() OVER (ORDER BY action_count DESC) as wallet_rankFROM wallet_ranks),bottom_50_threshold AS (SELECTMIN(cumulative_actions) as bottom_50_start_cumulative,MAX(total_actions) as total_actions,MAX(total_wallets) as total_walletsFROM wallet_percentilesWHERE wallet_rank <= FLOOR(total_wallets * 0.5))SELECTCAST((t.total_actions - t.bottom_50_start_cumulative) AS DOUBLE) / t.total_actions * 100 as bottom_50_pct_share,t.total_actions,t.bottom_50_start_cumulative as top_50_actions,t.total_actions - t.bottom_50_start_cumulative as bottom_50_actions,t.total_walletsFROM bottom_50_threshold t