with collections as ( select contract_address,EVENT_INPUTS:tokenId as nft
from ethereum.core.fact_event_logs
where origin_to_address = lower('0x5a7749f83b81b301cab5f48eb8516b986daef23d') and
origin_to_address = EVENT_INPUTS:to and origin_from_address = EVENT_INPUTS:from
)
,
label as ( select label , contract_address, nft
from ethereum.core.dim_labels a join collections b on a.address = b.contract_address)
,
last_price as ( select max(block_timestamp) as max_date , label, nft, price_usd , contract_address
from ethereum.core.ez_nft_sales a join label b on a.nft_address = b.contract_address and tokenid = nft
group by 2,3,4,5)
select label,contract_address, avg(price_usd) as avg_price
from last_price
group by 1,2
order by 3 desc
limit 10