# Counting pageviews per topic using the Data-Explorer plugin

**URL:** <https://meta.discourse.org/t/counting-pageviews-per-topic-using-the-data-explorer-plugin/112417>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [March 23, 2019, 5:28pm UTC](https://meta.discourse.org/t/counting-pageviews-per-topic-using-the-data-explorer-plugin/112417 "2019-03-23T17:28:18Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)\
**Post date:** [March 27, 2019, 12:25am UTC](https://meta.discourse.org/t/counting-pageviews-per-topic-using-the-data-explorer-plugin/112417/12 "2019-03-27T00:25:05Z")

</div>

Hi Alexandra,

Until a refactor takes places, I believe the following is the best we can do:

```sql
-- [params]
-- date :view_date = 2019-03-26
SELECT t.id AS topic_id, COUNT(t.id) AS first_time_views
FROM topics t 
JOIN topic_views tv ON t.id = tv.topic_id
GROUP BY t.id, viewed_at
HAVING viewed_at = :view_date
ORDER BY first_time_views DESC

```

You can specify a date using the field in the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) UI. The first column of the results will show linked topic titles with their reply count in parenthesis. The second column is the number of first time views of the topic on the day you specified.

---

_[View the full topic](https://meta.discourse.org/t/counting-pageviews-per-topic-using-the-data-explorer-plugin/112417)._
