Afonso_Diazgrouping users
    Updated 2024-10-10
    with main as (
    select
    tx_id,
    block_timestamp,
    authorizers[0] as user,
    event_data:amount as tx_fee
    from flow.core.fact_transactions
    join flow.core.fact_events
    using (tx_id)
    where tx_succeeded = 1
    and event_contract = 'A.f919ee77447b7497.FlowFees'
    and event_Type = 'FeesDeducted'
    and block_timestamp::date between case '{{ type }}'
    when 'daily' then date('{{ end_date }}') - interval '1 day'
    when 'weekly' then date('{{ end_date }}') - interval '1 week'
    when 'monthly' then date('{{ end_date }}') - interval '1 month'
    when 'yearly' then date('{{ end_date }}') - interval '1 year'
    end and '{{ end_date }}'
    ),

    users as (
    select
    user,
    count(distinct tx_id) as transactions
    from main
    group by 1
    )

    select
    case
    when transactions = 1 then 'a. 1 Transaction'
    when transactions <= 5 then 'b. 2 - 5 Transactions'
    when transactions <= 10 then 'c. 6 - 10 Transactions'
    when transactions <= 25 then 'd. 11 - 25 Transactions'
    when transactions <= 50 then 'e. 26 - 50 Transactions'
    else 'f. > 50 Transactions'
    QueryRunArchived: QueryRun has been archived