Most Direct Messages (interval)

A top ten list of users who have sent the most messages in the given timeframe.

-- [params]
-- string :interval = 1 WEEK

SELECT 
    user_id, 
    COUNT(*)
FROM chat_messages
WHERE created_at::date > CURRENT_DATE - INTERVAL :interval
GROUP BY user_id
ORDER BY COUNT(*) DESC
LIMIT 10