# Data Explorer query for topics N+ days old, that are unsolved

**URL:** https://meta.discourse.org/t/data-explorer-query-for-topics-n-days-old-that-are-unsolved/272020
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [July 18, 2023, 8:29pm UTC](https://meta.discourse.org/t/data-explorer-query-for-topics-n-days-old-that-are-unsolved/272020 "2023-07-18T20:29:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)
#### Post date: [July 18, 2023, 8:29pm UTC](https://meta.discourse.org/t/data-explorer-query-for-topics-n-days-old-that-are-unsolved/272020/1 "2023-07-18T20:29:27Z")

</div>

I am trying to create a [data explorer](https://meta.discourse.org/t/32566?silent=true) query that returns a list of topics, where:

- The topic is unsolved
- The topic is 7+ days old from the current date ran

---

<div class="post-metadata">

### Author: ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)
#### Post date: [July 18, 2023, 9:15pm UTC](https://meta.discourse.org/t/data-explorer-query-for-topics-n-days-old-that-are-unsolved/272020/2 "2023-07-18T21:15:35Z")

</div>

I eventually got unstuck! For anyone else looking for this. This query is for unsolved topics between 7 and 40 days old.

```plaintext
WITH solved_topics AS (

SELECT ua.target_topic_id AS topic_id,
       ua.user_id,
       ua.target_post_id AS post_id,
       p.created_at
FROM user_actions ua
JOIN posts p on p.id = ua.target_post_id
WHERE action_type = 15

)

SELECT t.id as topic_id,
       t.user_id AS question_user_id,
       t.created_at::date AS "Topic Posted On:",
       t.views
FROM topics t
LEFT JOIN solved_topics st ON t.id = st.topic_id
WHERE t.category_id = 37
AND t.created_at BETWEEN current_date - 40 AND current_date -7
AND t.deleted_at ISNULL
AND t.visible = TRUE
AND st.topic_id IS NULL
ORDER BY t.created_at

```

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [July 19, 2023, 8:47am UTC](https://meta.discourse.org/t/data-explorer-query-for-topics-n-days-old-that-are-unsolved/272020/3 "2023-07-19T08:47:51Z")

</div>

I’m glad you figured it out. 🙂

It might not be very useful for just two numbers, but just in case you wouldn’t know that, you can add dynamic parameters to [data explorer](https://meta.discourse.org/t/32566?silent=true) queries, which would allow you to easily select the range with inputs instead of directly editing the query: [https://meta.discourse.org/t/discourse-data-explorer/32566#declaring-parameters-in-your-query-8](https://meta.discourse.org/t/discourse-data-explorer/32566#declaring-parameters-in-your-query-8)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 18, 2023, 8:48am UTC](https://meta.discourse.org/t/data-explorer-query-for-topics-n-days-old-that-are-unsolved/272020/4 "2023-08-18T08:48:26Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
