Query editor
WITH config AS (SELECT 0x01791F726B4103694969820be083196cC7c045fF AS token_address, 0x17C61f4a7f41b96eb9c0D8805255b8411387c63b AS sender_address, 18 AS decimals),distributions AS (SELECT evt_block_time AS dist_time, "to" AS investor, value / power(10, (SELECT decimals FROM config)) AS amount_receivedFROM erc20_ethereum.evt_TransferWHERE contract_address = (SELECT token_address FROM config) AND "from" = (SELECT sender_address FROM config)AND "to" NOT IN (0x8235c179e9e84688fbd8b12295efc26834dac211, 0x76c941b6551b64e160b6d0107df9552331053f43)),outgoing AS (SELECT t.evt_block_time, t."from" AS investor, t.value / power(10, (SELECT decimals FROM config)) AS amount_sent, date_diff('hour', d.dist_time, t.evt_block_time) AS hours_since_receiptFROM erc20_ethereum.evt_Transfer tJOIN distributions d ON t."from" = d.investorWHERE t.contract_address = (SELECT token_address FROM config) AND t.evt_block_time > d.dist_time AND t."from" != 0x76c941b6551b64e160b6d0107df9552331053f43),raw_summary AS (SELECT d.investor, MAX(d.amount_received) AS total_received,COALESCE(SUM(CASE WHEN o.hours_since_receipt <= 24 THEN o.amount_sent ELSE 0 END), 0) AS raw_sold_24h,COALESCE(SUM(CASE WHEN o.hours_since_receipt > 24 AND o.hours_since_receipt <= 48 THEN o.amount_sent ELSE 0 END), 0) AS raw_sold_48h,COALESCE(SUM(CASE WHEN o.hours_since_receipt > 48 THEN o.amount_sent ELSE 0 END), 0) AS raw_sold_afterFROM distributions d LEFT JOIN outgoing o ON d.investor = o.investorWHERE d.investor != 0x76c941b6551b64e160b6d0107df9552331053f43 GROUP BY 1),clean_summary AS (SELECT investor, total_received,LEAST(total_received, raw_sold_24h) AS sold_within_24h,LEAST(GREATEST(0, total_received - raw_sold_24h), raw_sold_48h) AS sold_24h_to_48h,LEAST(GREATEST(0, total_received - raw_sold_24h - raw_sold_48h), raw_sold_after) AS sold_after_48hFROM raw_summary)SELECTSUM(total_received) AS total_tokens_distributed,SUM(sold_within_24h + sold_24h_to_48h + sold_after_48h) AS total_tokens_sold_overall,(SUM(sold_within_24h + sold_24h_to_48h + sold_after_48h) * 100.0 / SUM(total_received)) AS pct_total_sold_overall,SUM(sold_within_24h) AS tokens_sold_first_24h,(SUM(sold_within_24h) * 100.0 / SUM(total_received)) AS pct_sold_first_24h,SUM(sold_24h_to_48h) AS tokens_sold_specifically_24h_to_48h,(SUM(sold_24h_to_48h) * 100.0 / SUM(total_received)) AS pct_sold_specifically_24h_to_48h,SUM(sold_within_24h + sold_24h_to_48h) AS tokens_sold_cumulative_48h,(SUM(sold_within_24h + sold_24h_to_48h) * 100.0 / SUM(total_received)) AS pct_sold_cumulative_48h,SUM(sold_after_48h) AS tokens_sold_after_48h,(SUM(sold_after_48h) * 100.0 / SUM(total_received)) AS pct_sold_after_48h,SUM(total_received - (sold_within_24h + sold_24h_to_48h + sold_after_48h)) AS tokens_currently_held,(SUM(total_received - (sold_within_24h + sold_24h_to_48h + sold_after_48h)) * 100.0 / SUM(total_received)) AS pct_tokens_held,-- NEW: Investors who sold nothing (Diamond Hands Count) --COUNT(CASE WHEN (sold_within_24h + sold_24h_to_48h + sold_after_48h) = 0 THEN 1 END) AS investors_who_sold_nothing,(COUNT(CASE WHEN (sold_within_24h + sold_24h_to_48h + sold_after_48h) = 0 THEN 1 END) * 100.0 / COUNT(*)) AS pct_investors_who_sold_nothing,-- NEW: Investors who sold and are left with < 1 token (Dust) --COUNT(CASEWHEN (sold_within_24h + sold_24h_to_48h + sold_after_48h) > 0AND (total_received - (sold_within_24h + sold_24h_to_48h + sold_after_48h)) < 1THEN 1