libruaryAllOwnersPart3
    Updated 2024-10-17
    WITH Minted AS (
    SELECT
    event_data:id AS nft_id,
    CAST(event_data:editionID AS INT) AS edition_id
    FROM flow.core.fact_events
    WHERE event_contract = 'A.edf9df96c92f4595.Pinnacle'
    AND event_type = 'PinNFTMinted'
    AND CAST(event_data:editionID AS INT) BETWEEN 201 AND 300 -- Limit to the first 100 editions
    ),
    Deposits AS (
    SELECT
    event_data:id AS nft_id,
    event_data:to AS wallet_address,
    MAX(block_timestamp) AS last_deposit_time -- Capture the most recent deposit time
    FROM flow.core.fact_events
    WHERE event_contract = 'A.edf9df96c92f4595.Pinnacle'
    AND event_type = 'Deposit'
    AND event_data:id IN (SELECT nft_id FROM Minted) -- Only include NFTs from the first 100 editions
    GROUP BY event_data:id, event_data:to -- Group by NFT ID and wallet address
    ),
    Withdrawals AS (
    SELECT
    event_data:id AS nft_id,
    MAX(block_timestamp) AS withdrawal_time -- Capture the most recent withdrawal time
    FROM flow.core.fact_events
    WHERE event_contract = 'A.edf9df96c92f4595.Pinnacle'
    AND event_type = 'Withdraw'
    AND event_data:id IN (SELECT nft_id FROM Minted) -- Only include NFTs from the first 100 editions
    GROUP BY event_data:id
    ),
    LastDeposits AS (
    SELECT
    d.nft_id,
    d.wallet_address,
    d.last_deposit_time
    FROM Deposits d
    QueryRunArchived: QueryRun has been archived