# Most Direct Messages (interval)

**URL:** https://meta.discourse.org/t/most-direct-messages-interval/277362
**Category:** Data & reporting
**Tags:** chat, sql-query
**Created:** [August 31, 2023, 2:37pm UTC](https://meta.discourse.org/t/most-direct-messages-interval/277362 "2023-08-31T14:37:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [August 31, 2023, 2:37pm UTC](https://meta.discourse.org/t/most-direct-messages-interval/277362/1 "2023-08-31T14:37:59Z")

</div>

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

```sql
-- [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

```
