From 944dfc72541f14e771d71fa9424f5d05cb491c4d Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Tue, 27 Dec 2022 13:31:32 -0500 Subject: [PATCH] Some useful SQL queries --- sql.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sql.md diff --git a/sql.md b/sql.md new file mode 100644 index 0000000..a6c7752 --- /dev/null +++ b/sql.md @@ -0,0 +1,24 @@ + +# Most common servers + +```SQL +SELECT COUNT(*), host FROM followers GROUP BY host ORDER BY count DESC; +``` + +# Most popular twitter users + +```SQL +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; +``` + +# Most active users + +```SQL +SELECT array_length(followings, 1) AS l, acct, host FROM followers ORDER BY l DESC; +``` + +# Lag + +```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; +```