with sales as (SELECT
NFT_ASSET_ID as x,
BLOCK_TIMESTAMP::date as Date,
TOTAL_SALES_AMOUNT_USD as Price
from algorand.nft.ez_nft_sales_fifa
WHERE SALE_TYPE = 'secondary'),
rarity as (SELECT
NFT_ASSET_ID as y,
RARITY
from algorand.nft.ez_nft_metadata_fifa ),
merge as (select *
from sales
inner join rarity on sales.x = rarity.y)
select
Date,
sum(Price),
RARITY
from merge
group by Date,RARITY