# Time to response

**URL:** https://meta.discourse.org/t/time-to-response/120808
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [June 19, 2019, 2:39pm UTC](https://meta.discourse.org/t/time-to-response/120808 "2019-06-19T14:39:29Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [June 20, 2019, 5:29pm UTC](https://meta.discourse.org/t/time-to-response/120808/4 "2019-06-20T17:29:08Z")

</div>

> [@Jeanne\_Bertrand](#):
>
> I search for it but in vain

There isn’t a field in the database for this. Discourse uses a method that’s called on the `Topic` class to calculate the time to first response. You can see the code for it here: [discourse/app/models/topic.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/models/topic.rb#L1240).

This is approximately the SQL query that is generated by the `time_to_first_response` method. It can be run as a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query:

```sql
SELECT t.id AS topic_id, AVG(t.hours)::float AS hours, t.created_at
FROM (
  SELECT t.id, t.created_at::date AS created_at, EXTRACT(EPOCH FROM MIN(p.created_at) - t.created_at)::float / 3600.0 AS hours
  FROM topics t
  LEFT JOIN posts p ON p.topic_id = t.id
  WHERE t.archetype = 'regular'
  AND t.deleted_at IS NULL
  AND p.deleted_at IS NULL
  AND p.post_number > 1
  AND p.user_id != t.user_id
  AND p.post_type = 1
  GROUP BY t.id
) t
GROUP BY t.created_at, t.id
ORDER BY hours DESC

```

---

_[View the full topic](https://meta.discourse.org/t/time-to-response/120808)._
