with sells as (
select
block_timestamp,
concat(NFT_COLLECTION, '-', NFT_ID) as tokenid,
BUYER,
PRICE,
lead(BUYER) over (partition by NFT_COLLECTION, NFT_ID order by block_timestamp asc) as next_buyer
from
flow.core.ez_nft_sales
where
NFT_COLLECTION like '%RaceDay%'
order by
block_timestamp asc
), last_buyers as (
select
*
from
sells
where next_buyer is null
), race_holders as (
select
distinct BUYER
from
last_buyers
),
other_collections_sells as (
select
block_timestamp,
NFT_COLLECTION,
BUYER,
PRICE,
lead(BUYER) over (partition by NFT_COLLECTION, NFT_ID order by block_timestamp asc) as next_buyer
from
flow.core.ez_nft_sales
where
not(NFT_COLLECTION like '%RaceDay%')