Query editor
With Consolidate AS(Selecttrader,contract_addressfrom dune.brightspear.result_consolidate),prices AS (Selectcontract_address,pricefrom dune.brightspear.result_solana_prices),Total_Contracts_Traded AS (SELECTtrader,COUNT(DISTINCT contract_address) AS total_contracts_traded-- Total contracts traded by each traderFROM dune.brightspear.result_consolidatewhere amount_bought > 50AND count_bought < 50GROUP BY trader),-- Subquery to calculate the count of positive profits per wallet (trader)Profit_Count AS (SELECTtrader,COUNT(DISTINCT contract_address) AS profitable_contracts_countFROM (SELECTtrader,contract_address,SUM(profit) AS total_profit_per_contractFROM dune.brightspear.result_consolidateWhere profit > 5000AND count_bought < 50AND amount_bought > 50GROUP BY trader, contract_address) AS filtered_profitsGROUP BY trader)SELECTA.trader AS trader,profitable_contracts_count,total_contracts_traded,TRY_CAST(profitable_contracts_count AS REAL) / TRY_CAST(total_contracts_traded AS REAL) as profit_ratio,A.contract_address AS contract_address,P.price as price,A.symbol,first_bought_time,first_sold_time,pool_creation_date,CASEWHEN first_sold_time IS NULL THEN 'genuine buyer'WHEN first_sold_time > first_bought_time AND first_sold_time - first_bought_time <= INTERVAL '5' minute THEN 'sniper'ELSE 'genuine buyer'END AS label_sniper,CASEWHEN first_bought_time < pool_creation_date THEN 'pf'