with sales as (
select
block_timestamp::date as date,
team,
sum(price) as sales_volume,
sum(sales_volume) over (order by date) as cumulative_sales_volume
from flow.core.fact_nft_sales a left join flow.core.dim_topshot_metadata b on a.nft_id = b.nft_id
where tx_succeeded = TRUE and
(marketplace = 'A.c1e4f4f4c4257510.TopShotMarketV3' or marketplace = 'A.c1e4f4f4c4257510.Market') and
currency = 'A.ead892083b3e2c6c.DapperUtilityCoin' and
team is not null
group by 1, 2
order by 3 desc
),
top as (
select
row_number() over (partition by date order by sales_volume desc) as rank,
date,
team,
sales_volume,
cumulative_sales_volume
from sales
order by 3 desc
)(
select *
from top
where rank < 6
)order by rank asc