CryptoGowdaStaked [ Near ]
    Updated 2023-04-17
    WITH
    daily_latest_block_id AS (
    SELECT
    address,
    DATE_TRUNC('day', block_timestamp) AS day,
    MAX(block_id) AS max_block_id
    FROM
    near.core.fact_staking_pool_balances
    GROUP BY
    address,
    day
    ),
    daily_latest_staking_balances AS (
    SELECT
    f.address,
    f.balance,
    f.block_timestamp,
    f.block_id,
    DATE_TRUNC('day', f.block_timestamp) AS day
    FROM
    near.core.fact_staking_pool_balances f
    JOIN daily_latest_block_id lb ON f.address = lb.address
    AND f.block_id = lb.max_block_id
    )
    SELECT
    day,
    SUM(balance) AS daily_staking_balance
    FROM
    daily_latest_staking_balances
    GROUP BY
    day
    ORDER BY
    day DESC;
    Run a query to Download Data