cloutier--bird.makeup/sql.md

46 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2022-12-27 13:31:32 -05:00
# 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;
```
2023-01-14 13:16:00 -05:00
```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;
```
2022-12-27 13:31:32 -05:00
# 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;
2023-01-14 13:16:00 -05:00
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;
2022-12-27 13:31:32 -05:00
```
2023-01-14 13:16:00 -05:00
2023-05-14 19:36:55 -04:00
Lag by shards:
```SQL
SELECT min(lastsync), mod(id, 100) FROM
(SELECT acct, id, lastsync FROM (SELECT unnest(followings) as follow FROM followers) AS f INNER JOIN twitter_users ON f.follow=twitter_users.id) AS f
GROUP BY mod
ORDER BY min;
```
2023-03-03 10:37:42 -05:00
# Connections
```SQL
SELECT SUM(cardinality(followings)) FROM followers;
```