Query editor
WITH Total_Contracts_Traded AS (SELECTtrader,COUNT(DISTINCT contract_address) AS total_contracts_traded -- Total contracts traded by each traderFROM query_4191703GROUP 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 query_4191703WHERE total_profit > 5000GROUP BY trader, contract_address) AS filtered_profitsGROUP BY trader),Profit_Count_zero AS (SELECTtrader,COUNT(DISTINCT contract_address) AS profitable_count_zeroFROM (SELECTtrader,contract_address,SUM(profit) AS total_profit_per_contractFROM query_4191703WHERE total_profit > 0GROUP BY trader, contract_address) AS filtered_profitsGROUP BY trader),-- Subquery to get the highest total profit contract per traderHighest_Profit_Contract AS (SELECTtrader,contract_address,SUM(profit) AS total_profit_per_contract,label1, -- Retrieve labelslabel2,label_sniper,label_size,ROW_NUMBER() OVER (PARTITION BY trader ORDER BY SUM(profit) DESC) AS rnFROM query_4191703WHERE profit > 0 -- Only consider profitable contractsGROUP BY trader, contract_address, label1, label2, label_sniper, label_size),PNL AS (SELECTA.trader,H.label1, -- Include labels from the highest profit contract