MLDZMNBase- distribution (# of NFTs held per address) by project
    Updated 2025-01-01
    -- distribution (# of NFTs held per address) by project

    with buy as (select
    BUYER_ADDRESS,
    NFT_ADDRESS,
    PROJECT_NAME,
    TOKENID,
    BLOCK_TIMESTAMP,


    from Base.nft.ez_nft_sales
    where 1=1
    and Block_timestamp >= '{{Start_date}}'
    and Block_timestamp <= '{{End_date}}'
    ),

    sell as (select
    s.SELLER_ADDRESS,
    s.NFT_ADDRESS,
    s.PROJECT_NAME,
    s.TOKENID,
    s.BLOCK_TIMESTAMP,


    from Base.nft.ez_nft_sales s
    left join buy b on s.SELLER_ADDRESS = b.BUYER_ADDRESS and s.TOKENID=b.TOKENID and s.BLOCK_TIMESTAMP > b.BLOCK_TIMESTAMP
    where 1=1
    and s.Block_timestamp >= '{{Start_date}}'
    and s.Block_timestamp <= '{{End_date}}'
    ),

    main as (select
    b.BUYER_ADDRESS,
    b.PROJECT_NAME,
    zeroifnull(count(distinct b.TOKENID)) as bought_nfts,
    zeroifnull(count(distinct s.TOKENID)) as sold_nfts,
    QueryRunArchived: QueryRun has been archived