SectorPnL QA - Holder List (Buy/Sell Dates)
    Updated 2022-10-09
    --Issues: Wallets and vaults trade to themselves in same date creating issues. See 106

    -- select *
    -- from (
    with buy as (
    select
    ROW_NUMBER() OVER (PARTITION BY nft_to_address, tokenid ORDER BY block_timestamp DESC) AS rank,
    block_timestamp as date,
    nft_to_address as wallet,
    tokenid
    from ethereum.core.ez_nft_transfers
    where nft_address = lower('0x08d7c0242953446436f34b4c78fe9da38c73668d')
    ),
    sell as (
    select
    ROW_NUMBER() OVER (PARTITION BY nft_from_address, tokenid ORDER BY block_timestamp DESC) AS rank,
    block_timestamp as date,
    NFT_FROM_ADDRESS as wallet,
    tokenid
    from ethereum.core.ez_nft_transfers
    where nft_address = lower('0x08d7c0242953446436f34b4c78fe9da38c73668d')
    )
    --select distinct wallet from (
    select
    Wallet,
    tokenid,
    buy_date,
    case when sell_date is null then current_date
    else sell_date end as sell_or_current_date,
    buy_rank,
    sell_rank
    from (
    select
    a.rank as buy_rank,
    Run a query to Download Data