SteemSQL Tutorial – Finding Inactive Steemians that You Follow


If you have a following list that you would like to unfollow if he/she is inactive for at least 7 days, you might run the following SQL query (thanks to STEEMSQL). Being inactive means that he/she did not make a post or comment.

1
2
3
4
5
6
7
8
9
10
select author, datediff(day, T.last, GetUTCDate()) 
from 
(
    select author, max(created) "last" 
    from Comments 
    where author in ('followingid1', 'followingid2' ...) 
    group by author
) T 
where 
    datediff(day, T.last, GetUTCDate()) > 7
select author, datediff(day, T.last, GetUTCDate()) 
from 
(
    select author, max(created) "last" 
    from Comments 
    where author in ('followingid1', 'followingid2' ...) 
    group by author
) T 
where 
    datediff(day, T.last, GetUTCDate()) > 7

The nested SQL groups the posts by author and returns the last activity time, store in column “last“. The main query then further filters out the active users by datediff(day, T.last, GetUTCDate()) > 7

We can further optimise this SQL by storing the date columns in the inner SQL query. The following IDs can be fetched by query the Followers view. So the query becomes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
select author, T.days
from 
(
    select author, max(created) "last", datediff(day, max(created), GetUTCDate()) "days"
    from Comments 
    where author in (
        select 
            following
        from
            followers
        where
            follower = 'justyy'     
    ) 
    group by author
) T 
where 
    T.days > 7
order by
    T.days desc
select author, T.days
from 
(
    select author, max(created) "last", datediff(day, max(created), GetUTCDate()) "days"
    from Comments 
    where author in (
        select 
            following
        from
            followers
        where
            follower = 'justyy'     
    ) 
    group by author
) T 
where 
    T.days > 7
order by
    T.days desc

The above query will list @justyy ‘s most inactive following user IDs, this gives results:

steemsql-inactive-users SteemSQL Tutorial - Finding Inactive Steemians that You Follow database mssql sql SteemIt

steemsql-inactive-users

STEEM SQL Tutorial

You may also like: SteemSQL 系列教程之 – 你的哪些好友已经好久没玩STEEM了?

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
585 words
Last Post: [Answer] Mathematics × Programming Competition #8 - Four Digit Calculator
Next Post: Steem API - Get Curation Stats

The Permanent URL is: SteemSQL Tutorial – Finding Inactive Steemians that You Follow

Leave a Reply