Query editor
WITH wallet_totals AS (-- Step 1: Calculate total bought and sold per walletSELECTholder,SUM(CASE WHEN change > 0 THEN change ELSE 0 END) as total_bought,ABS(SUM(CASE WHEN change < 0 THEN change ELSE 0 END)) as total_soldFROM (SELECT "to" AS holder, SUM(value / 1e18) AS change FROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa12cc123ba206d4031d1c7f6223d1c2ec249f4f3 GROUP BY 1UNION ALLSELECT "from" AS holder, -SUM(value / 1e18) AS change FROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa12cc123ba206d4031d1c7f6223d1c2ec249f4f3 GROUP BY 1) tGROUP BY 1),categorized_holders AS (-- Step 2: Assign a label based on those totalsSELECTholder,(total_bought - total_sold) as current_balance,CASEWHEN total_sold = 0 THEN '💎 Diamond Hand'WHEN total_sold < (total_bought * 0.2) THEN '⚖️ Strategic Accumulator'ELSE '📄 Paper Hand'END as behaviorFROM wallet_totalsWHERE (total_bought - total_sold) > 0)-- Step 3: Group by the labelSELECTbehavior,COUNT(*) as wallet_count,SUM(current_balance) as total_tokens_heldFROM categorized_holdersGROUP BY 1ORDER BY 2 DESC