I’ve adapted a report to create this query to see which users have posted the most X months ago & how many users in total have posted within that time period.
-- [params] -- int :months_ago = 1 WITH query_period AS ( SELECT date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' as period_start, date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' + INTERVAL '1 month' - INTERVAL '1 second' as period_end ) SELECT ua.user_id, count(1) AS post_count FROM user_actions ua INNER JOIN query_period qp ON ua.created_at >= qp.period_start AND ua.created_at <= qp.period_end INNER JOIN users u ON u.id = ua.user_id AND u.admin = 'f' AND u.moderator = 'f' GROUP BY ua.user_id ORDER BY post_count DESC
But I’m struggling to get the latter - the total number of users who posted within the time period. I think I just need a count of the number of users who’re included in the report. I’d be grateful if anyone has some pointers.
Edit - Scrap that, I can see that I can just get this from the total number of results -