ZSaed0.4 followers & following count
    Updated 2023-10-02
    with flat as (select
    *
    from near.social.fact_decoded_actions,
    table(
    FLATTEN( INPUT =>NODE_DATA:follow)
    )
    where NODE ='graph'
    and NODE_DATA:follow is not null
    )
    , follow as (
    select SIGNER_ID,key, max(BLOCK_TIMESTAMP) as date from flat
    where this not like '%null%'
    -- and SIGNER_ID= 'manzanal.near'
    group by SIGNER_ID,key
    )
    ,unfollow as
    (
    select SIGNER_ID,key, max(BLOCK_TIMESTAMP) as date from flat
    where this ilike '%null%'
    -- and SIGNER_ID= 'manzanal.near'
    group by SIGNER_ID,key
    )
    ,abslot_unfollow as (
    select unfollow.SIGNER_ID,unfollow.key
    from unfollow JOIN follow on(unfollow.SIGNER_ID = follow.SIGNER_ID AND
    unfollow.key = follow.key and unfollow.date > follow.date
    ))
    , following_count as (
    select follow.SIGNER_ID as user,count(DISTINCT follow.key) as num_following
    from follow left join abslot_unfollow as b on (
    follow.SIGNER_ID = b.SIGNER_ID
    and follow.KEY != b.key )
    where b.SIGNER_ID is null
    group by user
    )
    Run a query to Download Data