FatemeTheLady03 flow txs
    Updated 2023-03-24
    with new as
    (select event_contract
    from (select event_contract, min(block_timestamp) as blocktimestamp from flow.core.fact_events where tx_succeeded=1 group by 1)
    having blocktimestamp::date>='2023-02-10' and blocktimestamp::date<='2023-04-01')
    ,
    events_new as
    (
    select
    case when event_data:from is not null then event_data:from
    when event_data:to is not null then event_data:to
    else event_data:address end as user,*
    from flow.core.fact_events
    where event_contract in (select event_contract from new)
    and tx_succeeded=1
    )

    ,
    events as (
    select
    case when event_data:from is not null then event_data:from
    when event_data:to is not null then event_data:to
    else event_data:address end as user,*
    from flow.core.fact_events
    where tx_succeeded=1
    )


    select
    date_trunc('day', block_timestamp) as "Timestamp",
    count(distinct tx_id) as "old-contract txs",
    count(distinct user) as "old-contract users",
    count( distinct case when tx_id in (select tx_id from events_new) then tx_id else null end) as "new-contract txs",
    count( distinct case when tx_id in (select tx_id from events_new) then user else null end) as "new-contract users"

    from events
    where block_timestamp::date>='2023-01-01' and block_timestamp::date<current_date
    Run a query to Download Data