From ba0017c18e9091fff6018b4daf641b62a0b9464c Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sat, 14 Jan 2023 13:16:00 -0500 Subject: [PATCH] interesting sql queries --- sql.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sql.md b/sql.md index a6c7752..b5965e5 100644 --- a/sql.md +++ b/sql.md @@ -11,6 +11,10 @@ SELECT COUNT(*), host FROM followers GROUP BY host ORDER BY count DESC; SELECT COUNT(*), acct FROM (SELECT unnest(followings) as follow FROM followers) AS f INNER JOIN twitter_users ON f.follow=twitter_users.id GROUP BY acct ORDER BY count DESC; ``` +```SQL +SELECT COUNT(*), acct, id FROM (SELECT unnest(followings) as follow FROM followers) AS f INNER JOIN twitter_users ON f.follow=twitter_users.id WHERE id IN ( SELECT unnest(followings) FROM followers WHERE host='social.librem.one' AND acct = 'vincent' ) GROUP BY acct, id ORDER BY count DESC; +``` + # Most active users ```SQL @@ -21,4 +25,7 @@ SELECT array_length(followings, 1) AS l, acct, host FROM followers ORDER BY l DE ```SQL SELECT COUNT(*), date_trunc('day', lastsync) FROM (SELECT unnest(followings) as follow FROM followers GROUP BY follow) AS f INNER JOIN twitter_users ON f.follow=twitter_users.id GROUP BY date_trunc; + +SELECT COUNT(*), date_trunc('hour', lastsync) FROM (SELECT unnest(followings) as follow FROM followers GROUP BY follow) AS f INNER JOIN twitter_users ON f.follow=twitter_users.id GROUP BY date_trunc ORDER BY date_trunc; ``` +