Query editor
-- 1. Identify frequently trading pairs of accountsWITH FrequentPairs AS (SELECTtx_from,tx_to,COUNT(*) AS trade_countFROMdex.tradesGROUP BYtx_from, tx_toHAVINGCOUNT(*) > 10 -- This threshold might need adjustment based on actual data),-- 2. For each account, determine its primary associatePrimaryAssociates AS (SELECTtx_from,tx_to AS primary_associate,ROW_NUMBER() OVER(PARTITION BY tx_from ORDER BY trade_count DESC) AS rnkFROMFrequentPairs)-- 3. Join with the trades table to map transactions to their primary associate account, RemappedTrades AS (SELECTt.project AS dex,CASEWHEN pa.rnk = 1 THEN pa.primary_associateELSE t.tx_fromEND AS mapped_account,t.amount_usdFROMdex.trades tLEFT JOINPrimaryAssociates pa ON t.tx_from = pa.tx_from)-- 4. Aggregate the transaction data by DEX and mapped accountSELECTdex,mapped_account AS account,SUM(amount_usd) AS total_amountFROMRemappedTradesGROUP BYdex, mapped_accountORDER BYdex, total_amount DESC;