with mintable as (
select buyer,
min (block_timestamp) as mindate
from flow.nft.ez_nft_sales
where tx_succeeded ilike 'TRUE'
group by 1),
maintable as (
select buyer,
min (block_timestamp) as mindate
from flow.nft.ez_nft_sales
where tx_succeeded ilike 'TRUE'
and substr(nft_collection,20) ilike '%{{NFT_Collection}}%'
group by 1)
select date_trunc ('{{Time_Interval}}',t2.mindate) as date,
case when t1.mindate = t2.mindate then 'First Purchased NFT Was Selected Project' else 'Was Not Selected Project' end as type,
count (distinct t1.buyer) as Buyers
from maintable t1 join mintable t2 on t1.buyer = t2.buyer
where t2.mindate >= '{{Start_Date}}' and t2.mindate <= '{{End_Date}}'
group by 1,2
order by 1 desc