Query editor
with b0 as (select * from query_8978264),b1 as (select *,case when n_claims = 0 then 'never' when last_claim < date '2025-10-01' then 'stale'when last_claim >= current_date - interval '90' day then 'recent90' else 'mid' end claim_status,case when cur < 1 then 'full_exit' when cur < 0.95*peak then 'partial_exit'when cur > 1.05*first_bal then 'added' else 'flat' end behavior,case when alloc_funded = 1 then 'A1 alloc-Safe-funded (direct)'when alloc_2hop = 1 then 'A2 alloc lineage (2-hop)'when cbp_funded = 1 or cbp_2hop = 1 then 'B Coinbase-Prime-funded (1-2 hop)'when wallet_type <> 'EOA' then 'C ' || wallet_typewhen airdrop = 1 then 'D EOA stakedrop/airdrop recipient'else 'E EOA other' end custody,if(first_d < date '2026-07-01', 'staked before 2026-07', 'staked 2026-07+') cohort2,(to_cex > 0 or dex_sold > 0) cexdex,date_diff('day', first_d, if(cur < 1, last_d, current_date)) tenure_days,cast(date_trunc('quarter', first_d) as varchar) tenure_q,greatest(accrued - claimed, 0) unclaimed_posfrom b0),b as (select b1.*, p.pop, if(p.pop = 'cur', cur, peak) basis,case when if(p.pop = 'cur', cur, peak) < 1e3 then '1 <1K' when if(p.pop = 'cur', cur, peak) < 1e4 then '2 1K-10K'when if(p.pop = 'cur', cur, peak) < 1e5 then '3 10K-100K' when if(p.pop = 'cur', cur, peak) < 1e6 then '4 100K-1M' else '5 1M+' end bucketfrom b1 cross join unnest(array['cur','all']) p(pop)where p.pop = 'all' or b1.cur > 1)select pop,case when grouping(bucket)=0 and grouping(custody)=0 then 'bucket_x_custody'when grouping(custody)=0 and grouping(claim_status)=0 then 'custody_x_claim'when grouping(bucket)=0 then 'bucket' when grouping(tenure_q)=0 then 'tenure' when grouping(custody)=0 then 'custody'when grouping(wallet_type)=0 then 'wallet' when grouping(claim_status)=0 then 'claim_status' when grouping(cohort2)=0 then 'cohort2' else 'total' end dim,coalesce(bucket,'') bucket, coalesce(tenure_q,'') tenure_q, coalesce(custody,'') custody, coalesce(wallet_type,'') wallet_type, coalesce(claim_status,'') claim_status, coalesce(cohort2,'') cohort2,count(*) n, sum(basis) stake, sum(cur) cur_stake, sum(peak) peak_stake,count_if(claim_status='never') n_never, sum(if(claim_status='never', basis, 0)) s_never,count_if(claim_status='stale') n_stale, sum(if(claim_status='stale', basis, 0)) s_stale,count_if(claim_status='mid') n_mid, sum(if(claim_status='mid', basis, 0)) s_mid,count_if(claim_status='recent90') n_recent, sum(if(claim_status='recent90', basis, 0)) s_recent,sum(accrued) accrued, sum(claimed) claimed, sum(unclaimed_pos) unclaimed_pos, sum(if(claim_status='never', accrued, 0)) unclaimed_never,count_if(behavior='added') n_added, count_if(behavior='flat') n_flat, count_if(behavior='partial_exit') n_partial, count_if(behavior='full_exit') n_full,sum(if(behavior='added', peak,0)) pk_added, sum(if(behavior='flat', peak,0)) pk_flat, sum(if(behavior='partial_exit', peak,0)) pk_partial, sum(if(behavior='full_exit', peak,0)) pk_full,count_if(cexdex) n_cexdex, sum(if(cexdex, basis, 0)) s_cexdex, count_if(eigen_out > 0) n_out, sum(if(eigen_out>0, basis, 0)) s_out,approx_percentile(tenure_days, 0.5) med_tenure, sum(tenure_days * basis)/nullif(sum(basis),0) wavg_tenure,count_if(wallet_type='EOA') n_eoa, count_if(wallet_type='EOA' and n_tx_after = 0) n_eoa_dormant, sum(if(wallet_type='EOA' and n_tx_after = 0, basis, 0)) s_eoa_dormant,count_if(wallet_type='EOA' and n_tx_after > 0 and last_tx < current_date - interval '180' day) n_eoa_quiet180,count_if(wallet_type='EOA' and last_tx >= current_date - interval '90' day) n_eoa_active90from bgroup by grouping sets ((pop), (pop, bucket), (pop, tenure_q), (pop, custody), (pop, wallet_type), (pop, claim_status), (pop, cohort2), (pop, bucket, custody), (pop, custody, claim_status))order by 1, 2, 3, 4, 5, 6, 7, 8