with source as (
select
date_trunc('week', block_timestamp) as TIME,
contract_address,
sum(sales_amount)/pow(10,6) as volume,
row_number() over (partition by TIME order by volume desc) as rank,
label
from terra.core.fact_nft_sales s left join terra.core.dim_address_labels l on l.address = s.contract_address
where TX_SUCCEEDED = 'TRUE'
and block_timestamp >= CURRENT_DATE - {{Past_X_Days}}
group by TIME, contract_address,label)
select * from source
having rank <= 3