Query editor
select rank, token_id, rarity_total, pct_rank,case when pct_rank >= 0.99 then 'top 1'when pct_rank >= 0.95 and pct_rank < 0.99 then 'top 5'when pct_rank >= 0.90 and pct_rank < 0.99 then 'top 10'when pct_rank >= 0.75 and pct_rank < 0.90 then 'top 25'when pct_rank >= 0.50 and pct_rank < 0.75 then 'top 50'else 'bottom 50'end as groupfrom (select token_id::numeric, sum(trait_rarity_value)*100 as rarity_total, row_number() over(order by sum(trait_rarity_value) desc ) as rank,percent_rank() over(order by sum(trait_rarity_value) asc ) as pct_rankfrom(select distinct token_id, t.key, t.value, c.cnt, 1/c.cnt as trait_rarity_valuefrom reservoir.token_attributes tleft join (select key, value, cnt, collection_id from (with base as (select key, value, count(value) as cnt, collection_idfrom reservoir.token_attributes ainner join reservoir.collections c on c.id = a.collection_idwhere '{{NFT Collection}}' = c.slug OR '{{NFT Collection}}' = c.id OR '{{NFT Collection}}' = c.contractgroup by key, value, collection_id )select *, count(*) over (partition by base.key) as key_count from base) where key_count < 50) con t.value = c.value and t.key = c.key and t.collection_id = c.collection_idinner join reservoir.collections c on c.id = t.collection_idwhere '{{NFT Collection}}' = c.slug OR '{{NFT Collection}}' = t.collection_id OR '{{NFT Collection}}' = c.contractorder by token_id ) agroup by 1order by 3 asc ) q--limit 1000