We use this one in my community to see the most active users in the last 30 days.
SELECT
u.username,
COUNT(c.*) AS cnt
FROM
chat_messages AS c
LEFT JOIN users AS u ON c.user_id = u.id
WHERE c.created_at >= CURRENT_TIMESTAMP - INTERVAL '30 days'
GROUP BY u.username
ORDER BY cnt DESC