# שאילתת Discourse לזמן קריאה כולל

**URL:** https://meta.discourse.org/t/discourse-query-for-total-read-time/279717
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [21 בספטמבר,‏ 2023,‏ 6:37pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717 "2023-09-21T18:37:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![codergautam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codergautam/32/261083_2.png) [@codergautam](https://meta.discourse.org/u/codergautam)
#### Post date: [21 בספטמבר,‏ 2023,‏ 6:37pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717/1 "2023-09-21T18:37:15Z")

</div>

I want to use Discourse [Data Explorer](https://meta.discourse.org/t/32566?silent=true) to see total user minutes of how long my user’s are reading. Then we could modify that query to see how long the average user is reading which would also be beneficial.

Is this possible?

---

<div class="post-metadata">

### Author: ![packman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/packman/32/289322_2.png) [@packman](https://meta.discourse.org/u/packman)
#### Post date: [21 בספטמבר,‏ 2023,‏ 6:50pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717/2 "2023-09-21T18:50:48Z")

</div>

A very quick and easy query is…

```plaintext
SELECT user_id, time_read FROM user_stats ORDER BY time_read DESC

```

That gives you read time for all users in descending order of read time.

---

<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: [21 בספטמבר,‏ 2023,‏ 6:54pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717/3 "2023-09-21T18:54:19Z")

</div>

Also, there are a few queries in this topic that could be a good starting place: [Data explorer query to list the longest "estimated read time" topics?](https://meta.discourse.org/t/data-explorer-query-to-list-the-longest-estimated-read-time-topics/196761).

---

<div class="post-metadata">

### Author: ![codergautam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codergautam/32/261083_2.png) [@codergautam](https://meta.discourse.org/u/codergautam)
#### Post date: [21 בספטמבר,‏ 2023,‏ 8:32pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717/4 "2023-09-21T20:32:11Z")

</div>

is it possible to get it by day rather than by user? like X mins read this day

---

<div class="post-metadata">

### Author: ![codergautam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codergautam/32/261083_2.png) [@codergautam](https://meta.discourse.org/u/codergautam)
#### Post date: [21 בספטמבר,‏ 2023,‏ 10:22pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717/5 "2023-09-21T22:22:50Z")

</div>

I figured it out, this query gets total time spent by day:

```plaintext
SELECT visited_at, SUM(time_read * 60) AS total_user_secs
FROM user_visits
GROUP BY visited_at
ORDER BY visited_at

```

Example in my forum:

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/2/2/522e966d27b3112c3f9277b45c133a9e47163ebf.png)

---

<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: [21 בספטמבר,‏ 2023,‏ 10:49pm UTC](https://meta.discourse.org/t/discourse-query-for-total-read-time/279717/6 "2023-09-21T22:49:34Z")

</div>

> [@codergautam](#):
>
> `SUM(time_read * 60) AS total_user_secs`

I think `time_read` is already in seconds (so in minutes would be `time_read /60` and in hours would be `time_read /3600`)

> [@codergautam](#):
>
> Then we could modify that query to see how long the average user is reading which would also be beneficial.

I think if you wanted to look at a graph of the average reading time per user per day within a given timeframe, the query would look something like this:

```sql
-- [params]
-- date :start_date
-- date :end_date

SELECT 
    visited_at, 
    ROUND(AVG(time_read/60),2)::float AS total_minutes
FROM user_visits
WHERE visited_at BETWEEN :start_date AND :end_date
GROUP BY visited_at
ORDER BY visited_at

```

 ![average reading time (mins) Jan2023-Jun2023 inc.](https://global.discourse-cdn.com/meta/original/4X/d/6/2/d62b1d6deacfafb41cdfb9fd136b48af447f395d.png)
