Elprognerd3 - month activity by top contract copy
    Updated 2023-04-14
    -- forked from 3 - daily activity by top contract @ https://flipsidecrypto.xyz/edit/queries/909d1c73-a47b-43d8-a39c-f8e5377c6e2b

    with txs AS (
    SELECT
    x.BLOCK_TIMESTAMP as BLOCK_TIMESTAMP,
    x.TX_ID as tx,
    x.PROPOSER as user,
    y.EVENT_TYPE as type,
    y.EVENT_CONTRACT
    FROM flow.core.fact_transactions x JOIN flow.core.fact_events y ON x.TX_ID = y.TX_ID
    WHERE x.TX_SUCCEEDED = 'true'
    )
    SELECT
    Date_trunc('month', BLOCK_TIMESTAMP) as date,
    REVERSE(SUBSTRING(REVERSE(EVENT_CONTRACT), 1, CHARINDEX('.', REVERSE(EVENT_CONTRACT))-1)) as contract,
    count( DISTINCT tx) as "Number of monthly txns",
    count(DISTINCT user) as "Number of monthly active users"
    from txs
    GROUP BY 1, 2
    ORDER BY 1



    Run a query to Download Data