yasmin-n-d-r-h2023-07-31 09:01 PM
    Updated 2023-07-31
    WITH MonthlyUserActivity AS (
    SELECT
    DATE_TRUNC('month', block_timestamp) AS month,
    label_type ,
    LABEL_SUBTYPE ,
    PROJECT_NAME ,
    COUNT(DISTINCT origin_from_address) AS active_users
    FROM
    aurora.core.fact_logs
    JOIN
    crosschain.core.address_labels ON address = contract_address
    GROUP BY
    1, 2, 3, 4
    HAVING
    month IS NOT NULL
    )

    SELECT
    month,
    label_type,
    LABEL_SUBTYPE,
    project_name ,
    active_users AS total_active_users,
    rank_by_active_users
    FROM
    (
    SELECT
    TO_CHAR(month, 'YYYY-MM') AS month,
    label_type,
    label_subtype ,
    project_name,
    active_users,
    RANK() OVER(PARTITION BY label_type, label_subtype ,project_name ORDER BY active_users DESC) AS rank_by_active_users
    FROM
    MonthlyUserActivity
    ) AS ranked_data
    Run a query to Download Data