This query examines the current holders of a specific NFT contract and identifies other NFTs they hold. It aims to determine which other NFT collections are popular among these users, focusing on NFTs with a history of transactions above a certain price.
Steps:
1. `holders` CTE:
- Identifies the current holders of the specified NFT contract by finding the most recent transfer for each token.
- Uses `ROW_NUMBER()` to select only the latest transfer per token based on `block_timestamp`.
2. `other_nft_held` CTE:
- Filters for other NFTs held by the users identified in the `holders` CTE.
- Limits to contracts that have recorded transactions with prices above $50, suggesting more significant or valuable holdings.
3. Final SELECT:
- Aggregates data to determine the total number of NFTs held and the count of distinct users holding those NFTs.
- Applies custom labels for specific contracts (e.g., 'ENS', 'Fableborne Primordials') and groups other collections under 'others'.
- Excludes contracts that are the same as the primary NFT contract or known irrelevant addresses.
- Filters results to focus on NFTs that have been traded above $10 within the last month and are held by more than 2 users.
- Orders by the number of distinct users holding each NFT and limits results to the top 20.
*/
WITHholdersAS(
-- Identify the most recent holder for each token in the specified NFT contract