Query editor
WITH first_in AS (SELECT destination AS wallet, MIN(block_time) AS first_inFROM ton.jetton_eventsWHERE jetton_master = '0:F3EC0B5D5A7C97DA18BD14EDECBF26E05638B6218A7E39061E56504F469035B3'AND type IN ('transfer', 'mint')AND NOT tx_abortedAND destination IS NOT NULLGROUP BY 1),out_stats AS (SELECT source AS wallet, MIN(block_time) AS first_out, COUNT(*) AS out_countFROM ton.jetton_eventsWHERE jetton_master = '0:F3EC0B5D5A7C97DA18BD14EDECBF26E05638B6218A7E39061E56504F469035B3'AND type IN ('transfer', 'burn')AND NOT tx_abortedAND source IS NOT NULLGROUP BY 1),current_bal AS (SELECT address, amount FROM (SELECT address, amount,ROW_NUMBER() OVER (PARTITION BY address ORDER BY lt DESC) AS rnFROM ton.balances_historyWHERE asset = '0:F3EC0B5D5A7C97DA18BD14EDECBF26E05638B6218A7E39061E56504F469035B3') WHERE rn = 1 AND amount > 0),wallets AS (SELECTi.wallet,i.first_in,o.first_out,COALESCE(o.out_count, 0) AS out_count,b.amount AS current_amountFROM first_in iLEFT JOIN out_stats o ON o.wallet = i.walletLEFT JOIN current_bal b ON b.address = i.wallet),agg AS (SELECTCOUNT_IF(current_amount > 0 AND first_out IS NULL AND first_in < now() - interval '30' day) AS diamond_hands,COUNT_IF(current_amount > 0 AND first_out IS NULL AND first_in < now() - interval '10' day) AS potential_diamond,COUNT_IF(current_amount > 0 AND first_in < now() - interval '180' day AND out_count < 5) AS strong_apes,COUNT_IF(current_amount > 0) AS current_holdersFROM wallets)SELECTdiamond_hands,CAST(ROUND(100.0 * diamond_hands / NULLIF(current_holders, 0), 1) AS double) AS diamond_pct,potential_diamond,CAST(ROUND(100.0 * potential_diamond / NULLIF(current_holders, 0), 1) AS double) AS potential_pct,strong_apes,CAST(ROUND(100.0 * strong_apes / NULLIF(current_holders, 0), 1) AS double) AS strong_apes_pct,current_holdersFROM agg