Query editor
-- Diamond Hand Curve - Survival Analysis by Holding Duration-- Shows attrition rate for tokens held X months before being sold-- Answers: "Of tokens held for 12+ months, what % were eventually sold?"-- Parameters:-- {{Timeframe}} - Sales lookback in days (dropdown: 30, 90, 180, 365, 730, 9999)-- Output: One row per (collection, holding_threshold) with attrition metrics-- ============================================================================-- COLLECTIONS & THRESHOLDS-- ============================================================================WITH collections AS (SELECT contract_address, blockchain, collection_key, collection_name FROM (VALUES(0xA3AEE8BCE55BEEA1951EF834B99F3AC60D1ABEEB, 'ethereum', 's1', 'Series 1'),(0x9378368ba6b85c1fba5b131b530f5f5bedf21a18, 'ethereum', 's2', 'Series 2'),(0x65FFF8F5F6A9922B6DC13FE06345A0FE46DD413D, 'ethereum', 'iconics', 'Iconics'),(0x6bb33db533dcc47d26570408559228d180bcd67c, 'base', 'bookgames', 'Book Games')) AS t(contract_address, blockchain, collection_key, collection_name)),-- Holding duration thresholds to sweep (months)thresholds AS (SELECT holding_months FROM (VALUES (0), (1), (6), (12), (24), (36), (48)) AS t(holding_months)),-- ============================================================================-- TOKEN UNIVERSE (total supply per collection)-- ============================================================================token_counts AS (SELECTc.collection_key,COUNT(DISTINCT tr.tokenId) AS total_tokensFROM erc721_ethereum.evt_Transfer trINNER JOIN collections cON tr.contract_address = c.contract_addressAND c.blockchain = 'ethereum'WHERE tr."from" = 0x0000000000000000000000000000000000000000 -- Mints onlyGROUP BY c.collection_keyUNION ALLSELECTc.collection_key,COUNT(DISTINCT tr.tokenId) AS total_tokensFROM erc721_base.evt_Transfer trINNER JOIN collections cON tr.contract_address = c.contract_addressAND c.blockchain = 'base'WHERE tr."from" = 0x0000000000000000000000000000000000000000GROUP BY c.collection_key),-- ============================================================================-- OWNERSHIP SPANS: Each wallet's holding period per token-- ============================================================================-- Single unified transfer stream per (collection, token). The prior code-- ran two UNION ALL branches — a "non-mint" branch filtered with-- `WHERE from != 0x0 OR to != 0x0` (which excludes nothing because a mint-- has from=0x0 to=wallet → second clause true) and a mint-only branch with-- its own LEAD(). A token that was minted then sold therefore appeared-- TWICE in the stream: once with the real mint→sale span, and once with