with price as (
select
timestamp::date as day,
avg(price_usd) as flow_price
from flow.core.fact_prices
where token_contract = 'A.1654653399040a61.FlowToken'
group by 1
),
base as (
select
*,
case
when currency in ('A.ead892083b3e2c6c.FlowUtilityToken', 'A.1654653399040a61.FlowToken') then price * flow_price else price end as nft_price
from flow.core.ez_nft_sales join price on block_timestamp::date = day
where
nft_collection = 'A.e4cf4bdc1751c65d.AllDay' and tx_succeeded = 'TRUE'
and block_timestamp>= '2022-11-17' and block_timestamp <='2022-12-01'
)
select *
from (
select
date(block_timestamp) as date,
team,
sum(nft_price) as sales_volume,
rank() over(partition by date order by sales_volume desc) as rank
from base f
JOIN flow.core.dim_allday_metadata m ON m.NFT_ID = f.NFT_ID
group by 1,2
order by sales_volume desc
)
where rank <= 5