Query editor
withprice as (select symbol , decimals, avg(token_price_usd) as pricefrom dex.prices_latest,tokens.erc20where token_address = 0x4498cd8Ba045E00673402353f5a4347562707e7Dand contract_address = 0x4498cd8Ba045E00673402353f5a4347562707e7Dand blockchain = 'base'group by 1,2),raw as (select "from" as address, sum(cast(value as double)*-1) as amountfromerc20_base.evt_Transferwhere contract_address = 0x4498cd8Ba045E00673402353f5a4347562707e7Dgroup by 1union allselect "to" as address, sum(cast(value as double)) as amountfrom erc20_base.evt_Transferwhere contract_address = 0x4498cd8Ba045E00673402353f5a4347562707e7Dgroup by 1)selectcasewhen percent_holdings >=0.5 then 'H) Holdings >=50%'when percent_holdings >=0.4 and percent_holdings<0.5 then 'G) Holdings >=40% & <50%'when percent_holdings >=0.3 and percent_holdings<0.4 then 'F) Holdings >=30% & <40%'when percent_holdings >=0.2 and percent_holdings<0.3 then 'E) Holdings >=20% & <30%'when percent_holdings >=0.1 and percent_holdings<0.2 then 'D) Holdings >=10% & <20%'when percent_holdings >=0.05 and percent_holdings<0.1 then 'C) Holdings >=5% & <10%'when percent_holdings >=0.01 and percent_holdings<0.05 then 'B) Holdings >=1% & <5%'when percent_holdings <0.01 then 'A) Holdings <1%'end as distribution,count(distinct address) as address_count,sum(holding) as total_holdingfrom (select-- case-- when address in (select distinct address from labels.cex_ethereum) then 'CEX'-- when address in (select distinct project_contract_address from dex.trades) then 'DEX'-- when address in (select distinct address from base.creation_traces)-- and address not in (select distinct project_contract_address from dex.trades) then 'Other Smart Contracts'-- else 'Individual Address'-- end as type,address,sum(amount/power(10,decimals)) as holding,sum(amount*price/power(10,decimals)) as holding_usd,sum(amount)/(select sum(amount) from raw where address not in (0x0000000000000000000000000000000000000000,0x000000000000000000000000000000000000dEaD,0xD15a672319Cf0352560eE76d9e89eAB0889046D3)) as percent_holdingsfrom price, rawwhere address not in (0x0000000000000000000000000000000000000000,0x000000000000000000000000000000000000dEaD,0xD15a672319Cf0352560eE76d9e89eAB0889046D3)group by 1)awhere holding_usd>1group by 1