SELECT
sum(p.score) / count(p) as "平均スコア",
count(p.id) as post_count,
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
GROUP by user_id, u.views
HAVING count(p.id) > 40
ORDER BY sum(p.score) / count(p) DESC
LIMIT 100
-- [params]
-- int_list :exclude_groups = 12, 2, 3
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
LEFT JOIN group_users gu on u.id = gu.user_id
WHERE p.created_at >= CURRENT_DATE - INTERVAL '3 month'
AND u.active
AND (gu.group_id not IN (:exclude_groups))
GROUP by p.user_id, u.views
HAVING count(p.id) > 40
ORDER BY sum(p.score) / count(p) DESC
LIMIT 100
-- [パラメータ]
-- 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