HosseinUntitled Query
    Updated 2022-11-28
    with
    deposited as (
    select event_data:to as user_address,
    sum(event_data:amount) as amount_in
    from flow.core.fact_events
    where event_type = 'TokensDeposited'
    and tx_succeeded = 1
    group by user_address
    ),

    withdrawn as (
    select event_data:from as user_address,
    sum(event_data:amount) as amount_out
    from flow.core.fact_events
    where event_type = 'TokensWithdrawn'
    and tx_succeeded = 1
    group by user_address
    ),

    main as (
    select user_addresss,
    ifnull(amount_in,0) as total_deposited, ifnull(amount_out,0) as total_withdrawn,
    total_deposited-total_withdrawn as current_balance
    from deposited
    join withdrawn using(user_address, event_contract)
    where
    deposited.user_address != 'null'
    and deposited.event_contract = 'A.1654653399040a61.FlowToken'
    )

    select
    count(distinct user_addresss) as FLOW_holders,
    sum(current_balance) as total_FLOW_tokens_in_balances,
    avg(current_balance) as avg_FLOW_tokens_in_balances
    from main where current_balance>0
    Run a query to Download Data