permaryupset-white
    Updated 2025-02-19
    WITH latest_ledger AS (
    SELECT MAX(sequence) as max_sequence
    FROM stellar.core.fact_ledgers
    )
    SELECT
    l.closed_at as latest_timestamp,
    COUNT(DISTINCT CASE WHEN a.deleted = FALSE THEN a.account_id END) as existing_accounts,
    COUNT(DISTINCT CASE WHEN a.deleted = TRUE THEN a.account_id END) as deleted_accounts,
    COUNT(DISTINCT a.account_id) as total_accounts
    FROM stellar.core.fact_ledgers l
    JOIN latest_ledger ll ON l.sequence = ll.max_sequence
    JOIN stellar.core.fact_accounts a ON 1=1
    GROUP BY 1;

    WITH daily_ledger AS (
    SELECT
    DATE(closed_at) AS day,
    MAX(sequence) AS max_sequence
    FROM stellar.core.fact_ledgers
    WHERE closed_at >= DATEADD(month, -12, CURRENT_DATE) -- Last 12 months
    GROUP BY 1
    )
    SELECT
    dl.day AS date,
    COUNT(DISTINCT CASE WHEN a.deleted = FALSE THEN a.account_id END) AS existing_accounts,
    COUNT(DISTINCT CASE WHEN a.deleted = TRUE THEN a.account_id END) AS deleted_accounts,
    COUNT(DISTINCT a.account_id) AS total_accounts
    FROM daily_ledger dl
    JOIN stellar.core.fact_ledgers l ON dl.max_sequence = l.sequence
    JOIN stellar.core.fact_accounts a ON 1=1
    GROUP BY 1
    ORDER BY 1;


    WITH daily_latest_ledger AS (
    SELECT
    Last run: 2 months ago
    MONTH
    EXISTING_ACCOUNTS
    DELETED_ACCOUNTS
    TOTAL_ACCOUNTS
    1
    2025-02-01 00:00:00.0001940194
    2
    2025-01-01 00:00:00.0001941195
    3
    2024-12-01 00:00:00.0003580358
    4
    2024-11-01 00:00:00.0002770277
    5
    2024-10-01 00:00:00.0001920192
    6
    2024-09-01 00:00:00.0002320232
    7
    2024-08-01 00:00:00.0002870287
    8
    2024-07-01 00:00:00.0002491250
    9
    2024-06-01 00:00:00.0001610161
    10
    2024-05-01 00:00:00.0001780178
    11
    2024-04-01 00:00:00.0003520352
    12
    2024-03-01 00:00:00.0002500250
    13
    2024-02-01 00:00:00.0004840484
    13
    495B
    3s