with sales as (
select
case
when PROJECT_NAME is null then nft_address
else initcap(PROJECT_NAME)
end as title,
ifnull(price_usd,0) as price_usdd,
*
from
ethereum.core.ez_nft_sales
), firstvals as (
select
title,
avg(price_usdd) as volume_usd
from
sales
where block_timestamp between '2022-01-01' and '2022-01-31'
group by title
), lastvals as (
select
title,
avg(price_usdd) as volume_usd
from
sales
where block_timestamp between '2022-12-01' and '2022-12-31'
group by title
)
select
l.volume_usd - f.volume_usd as diff,
row_number() over (order by diff desc) as rn,
concat(lpad(rn,3,'0'), ' - ', f.title) as title_rn
from
firstvals f join lastvals l on f.title=l.title
order by
rn asc
limit 50