Query editor
/*This query is built upon the query which fetches all token holders with their balances: https://dune.com/queries/3952814/6650135Query outputs the stats related to the holding and staking balances for the target token:1. Holding balances:- Unique holders count- Min / Max / Avg / Median / Q2 / Q3 / Std balance2. Staking balances:- Unique stakers count, EXCLUDING those stakers who got their tokens staked on their behalf (e.g. $MOCA on-behalf staking of Jul'2024)- Min / Max / Avg / Median / Q2 / Q3 / Std staking balance- Min / Max / Avg staked amount per wallet3. On-behalf staking (ONLY for staking pools where wallets get their tokens staked on their behalf, like $MOCA on-behalf staking of Jul'2024):- Count of wallets which unstaked their tokens staked on their behalf- Min unstaked amount / value of tokens staked on the wallet's behalf*/WITH/* 1. Fetching daily median token price on DEX's in USD. */dex_med_token_price AS (SELECTAPPROX_PERCENTILE(median_price, 0.5) AS med_token_price,DATE_TRUNC('day', hour) AS dayFROM dex.pricesWHERE contract_address = {{token_address}}GROUP BY DATE_TRUNC('day', hour)),latest_med_token_price AS (SELECT med_token_price AS last_token_priceFROM dex_med_token_priceORDER BY day DESCLIMIT 1),/*2. Calculating aggregate values from the holders & balances query for:- holders stats- stakers stats- on-behalf staking statsSee the top of the query for more elaborate explanation of the stats.*/holders_stats AS (SELECTCOUNT(wallet) AS holders_cnt,MIN(balance * price.last_token_price) AS min_balance,ROUND(MAX(balance * price.last_token_price), 2) AS max_balance,ROUND(AVG(balance * price.last_token_price), 2) AS avg_balance,ROUND(APPROX_PERCENTILE(balance * price.last_token_price, 0.25), 2) AS q2_balance,ROUND(APPROX_PERCENTILE(balance * price.last_token_price, 0.5), 2) AS med_balance,ROUND(APPROX_PERCENTILE(balance * price.last_token_price, 0.75), 2) AS q3_balance,STDDEV_POP(balance * price.last_token_price) AS balance_stdFROM query_3952814CROSS JOIN latest_med_token_price priceWHERE balance > 0),stakers_stats AS (SELECTCOUNT(wallet) AS stakers_cnt,MIN(staking_balance * price.last_token_price) AS min_staking_balance,