指定された期間のトップX投稿者

心配いりません。:slight_smile:

将来の旅行者のために、このようなものが役立つと思います。

-- [params]
-- date :start_date = 2024-05-01
-- date :end_date = 2024-05-31
-- int :top_x = 10
-- int :column_sort = 2

SELECT
    p.user_id,
    COUNT(*) AS "トピック+投稿",
    COUNT(*) FILTER (WHERE p.post_number = 1) AS "トピック",
    COUNT(*) FILTER (WHERE p.post_number <> 1) AS "投稿"
FROM posts p
  JOIN topics t ON t.id = p.topic_id
WHERE p.created_at::date BETWEEN :start_date AND :end_date
  AND t.archetype = 'regular'
  AND p.deleted_at ISNULL
  AND t.deleted_at ISNULL
  AND p.post_type = 1
  AND p.user_id > 0
GROUP BY p.user_id
ORDER BY :column_sort DESC
LIMIT :top_x
「いいね!」 3