Pine AnalyticsNeptune Metrics copy
    Updated 2025-01-23
    with tab1 as (
    SELECT
    tx.tx_id,
    block_timestamp,
    pre_bal.value AS pre_token_balance,
    post_bal.value AS post_token_balance,
    pre_token_balance['mint'] as token,
    pre_token_balance['owner'] as owner,
    pre_token_balance['uiTokenAmount']['amount'] / power(10, 9) as pre_balance,
    post_token_balance['uiTokenAmount']['amount'] / power(10, 9) as post_balance,
    post_balance - pre_balance as net_balance

    FROM
    eclipse.core.fact_transactions tx,
    LATERAL FLATTEN(input => tx.PRE_TOKEN_BALANCES) pre_bal,
    LATERAL FLATTEN(input => tx.POST_TOKEN_BALANCES) post_bal
    WHERE
    --tx.tx_id in ('4LbgsAWjjqJaVnbdHwbeU1Fv8PrCDR1ronsiqoX5A5eTQph8b7imDXbM1Qwm7FEDJrmy7Ee8c6wTRynHDYR7ZKiS', '3xFjC29bEmxXurU3bvbQYpJ8qpfz7nzwZGMZyENWcjvcWXjerHRepRAPHK6LfvQfBPwNNp5ZwR6pHhEz4wVDZa1g')
    pre_bal.index = post_bal.index;
    and token like 'FATF66HHhz8Yf2zxMXZXjmzu8NFArwtCJGEsj7rHC8i4'
    and SUCCEEDED
    )

    SELECT
    --*,
    --case when pre_balance = 0 and post_balance > 0 then 1 when post_balance = 0 and pre_balance > 0 then -1 else 0 end
    date_trunc('hour', block_timestamp) as hour,
    sum(case when pre_balance = 0 and post_balance > 0 then 1 when post_balance = 0 and pre_balance > 0 then -1 else 0 end) as net_holders,
    sum(net_holders) over (order by hour) as total_holders

    from tab1
    GROUP by 1
    order by 1 DESC


    QueryRunArchived: QueryRun has been archived