-- [パラメータ]
-- int_list :exclude_groups = 1,2
SELECT
sum(p.score) / count(p) as "投稿あたりの平均スコア",
count(p.id) as 投稿数,
p.user_id
FROM posts p
JOIN users u ON u.id = p.user_id
WHERE p.created_at >= CURRENT_DATE - INTERVAL '3 month'
AND u.active
AND u.id NOT IN(
SELECT user_id FROM group_users WHERE group_id IN (:exclude_groups)
)
GROUP BY user_id, u.views
HAVING count(p.id) > 40
ORDER BY sum(p.score) / count(p) DESC
LIMIT 100