Top X posters in a given timeframe

Ah no worries. :slight_smile:

For future travellers, I think something like this would do it:

-- [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 "Topics+Posts",
    COUNT(*) FILTER (WHERE p.post_number = 1) AS "Topics",
    COUNT(*) FILTER (WHERE p.post_number <> 1) AS "Posts"
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 Likes