Afonso_DiazGrouping users by active days
    Updated 2024-10-28
    with

    main as (
    select
    tx_hash,
    block_timestamp,
    decoded_log:maker as maker,
    decoded_log:taker as taker,
    decoded_log:fee / 1e18 AS fee,
    case
    when decoded_log:makerAssetId = 0 then decoded_log:makerAmountFilled
    when decoded_log:takerAssetId = 0 then decoded_log:takerAmountFilled
    end / 1e18 as amount
    from
    polygon.core.fact_decoded_event_logs
    where
    contract_address in ('0xc5d563a36ae78145c45a50134d48a1215220f80a', '0x4bfb41d5b3570defd03c39a9a4d8de6bd8b8982e')
    and event_name = 'OrderFilled'
    ),

    users as (
    select
    taker as user,
    count(distinct tx_hash) as transactions,
    count(distinct block_timestamp::date) as active_days
    from
    main
    group by 1
    )

    select
    case
    when active_days <= 7 then 'a. 1 days - 1 week'
    when active_days <= 14 then 'b. 1 week - 2 weeks'
    when active_days <= 30 then 'c. 2 weeks - 1 month'
    when active_days <= 90 then 'd. 1 month - 3 months'
    QueryRunArchived: QueryRun has been archived