# עזרה עם SQL - סגירה אוטומטית/תוצאות חוזרות/סינון שבועי

**URL:** <https://meta.discourse.org/t/help-with-sql-autoclose-repeat-results-week-filter/231038>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [24 ביוני,‏ 2022,‏ 5:25pm UTC](https://meta.discourse.org/t/help-with-sql-autoclose-repeat-results-week-filter/231038 "2022-06-24T17:25:17Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Matt0x01](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/matt0x01/32/264811_2.png) [@Matt0x01](https://meta.discourse.org/u/Matt0x01)\
**Post date:** [24 ביוני,‏ 2022,‏ 5:25pm UTC](https://meta.discourse.org/t/help-with-sql-autoclose-repeat-results-week-filter/231038/1 "2022-06-24T17:25:17Z")

</div>

Hey so I’ve created a query(at the bottom) that displays topic, category, the vote count of a topic, if its closed, when it was created and the user who has created. If more info is needed please feel free to let me know.

I have a few issues and questions I’d like some help or guidance with since I’m new to sql.

1. When running this query it displays the same topic hundreds of times over. How can I fix this

2. Is there any way to get and show when a topic will auto close?

3. I want only topics within a week to display. But the date\_trunc i added shows some items a little over a week ago?

```plaintext
SELECT
    t.id as topic_id,
    t.category_id,
    dvc.votes_count,
    t.closed,
    t.created_at,
    t.user_id
FROM topics t, discourse_voting_topic_vote_count dvc
WHERE t.closed = true
    AND t.category_id = 20
    AND dvc.votes_count >= 1
    AND t.created_at <= date_trunc('week', current_date)::date
    AND t.created_at >= date_trunc('week', current_date)::date - 7

```

---

_[View the full topic](https://meta.discourse.org/t/help-with-sql-autoclose-repeat-results-week-filter/231038)._
