# Is the info Top Referred Topics/ Top Traffic Sources stored in a table in the database?

**URL:** <https://meta.discourse.org/t/is-the-info-top-referred-topics-top-traffic-sources-stored-in-a-table-in-the-database/73301>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [November 2, 2017, 4:07pm UTC](https://meta.discourse.org/t/is-the-info-top-referred-topics-top-traffic-sources-stored-in-a-table-in-the-database/73301 "2017-11-02T16:07:09Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [January 10, 2020, 2:34am UTC](https://meta.discourse.org/t/is-the-info-top-referred-topics-top-traffic-sources-stored-in-a-table-in-the-database/73301/8 "2020-01-10T02:34:23Z")

</div>

Here is a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query that returns the top referred topics for a given time period. I’ll add a query for the top traffic sources soon.

The query returns a list of Discourse topics, and the number of times links to each topic have been clicked from an external source. The query requires you to supply start\_date and end\_date parameters in the form ‘yyyy-mm-dd’, for example `2020-01-08`. Results are ordered by click count in descending order. The top 100 referred topics for the time period are returned. If you need more results than that, adjust the query’s `LIMIT` value.

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

SELECT
t.id AS topic_id,
COUNT(p.id) AS external_click_count
FROM incoming_links il
JOIN posts p
ON p.id = il.post_id
JOIN topics t
ON t.id = p.topic_id
WHERE t.archetype = 'regular'
AND il.created_at::date BETWEEN :start_date::date AND :end_date::date
GROUP BY p.id, t.id
ORDER BY external_click_count DESC
LIMIT 100

```

---

_[View the full topic](https://meta.discourse.org/t/is-the-info-top-referred-topics-top-traffic-sources-stored-in-a-table-in-the-database/73301)._
