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:
STEEM SQL Tutorial
- SteemSQL Tutorial: How to Get Random Posts on SteemIt?
- SteemSQL Tutorial: How to Get Authors Order By Potential Payout in Last 7 days?
- SteemSQL Tutorial: How to Get Historic Posts of Today on SteemIt?
- SteemSQL Tutorial: How to Calculate Monthly Income on STEEMIT?
- SteemSQL Tutorial: Can we Really Recover Deleted Comments/Posts on STEEMIT?
- SteemSQL Tutorial: What are the Outgoing Votes for Big Whales?
- SteemSQL Tutorial: Count Total Interests Sent
- SteemSQL Tutorial: Finding Inactive Steemians that You Follow
- SteemSQL Tutorial: How to Fix “JSON text is not properly formated. Unexpected character ‘.’ is found at position 0.”?
- SteemSQL Tutorial: How to Get the Most Payout Authors in History?
- SteemSQL Tutorial: Get Most Single Payout Authors
- SteemSQL Tutorial: How to Avoid SQL Injection?
- SteemSQL Tutorial: I have spent 800 SBD (7000+ USD) buying votes!
- SteemSQL Tutorial: How to Check If SteemSQL is Synchronized with Steem Blockchain?
You may also like: SteemSQL 系列教程之 – 你的哪些好友已经好久没玩STEEM了?
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: [Answer] Mathematics × Programming Competition #8 - Four Digit Calculator
Next Post: Steem API - Get Curation Stats