# Data explorer 查询能否返回某些帖子通知？

**URL:** <https://meta.discourse.org/t/data-explorer-query-to-return-certain-post-notices/271090>\
**Category:** Data & reporting\
**Tags:** post-notices, sql-query\
**Created:** [2020 年11 月 18 日 03:07 UTC](https://meta.discourse.org/t/data-explorer-query-to-return-certain-post-notices/271090 "2020-11-18T03:07:16Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

作者： ![simonk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simonk/32/247950_2.png) [@simonk](https://meta.discourse.org/u/simonk)\
发布日期： [2020 年11 月 19 日 00:03 UTC](https://meta.discourse.org/t/data-explorer-query-to-return-certain-post-notices/271090/3 "2020-11-19T00:03:13Z")

</div>

> [@nathank](#):
>
> 可以通过设置一个回溯时间（例如一周或一个月）来改进，但这难住了我，因为我无法弄清楚如何让 `NOW() - 7` 或类似的表达式生效。

我认为您可以使用类似以下内容：

```sql
AND us.first_post_created_at > NOW() - INTERVAL '7 DAYS'

```

([postgresql 日期/时间文档](https://www.postgresql.org/docs/9.0/functions-datetime.html))

> [@nathank](#):
>
> 另外，排除私信（正如 @tshenry 的另一个查询所示）会非常棒，但作为 SQL 新手，我需要很长时间才能弄清楚如何实现。

要排除私信，您需要连接到 `topics` 表（遵循 `posts.topic_id` 外键），并检查 `archetype` 列。在 `WHERE` 子句之前添加以下内容：

```sql
JOIN topics t ON p.topic_id = t.id

```

…并在 `ORDER BY` 之前添加以下内容：

```sql
AND t.archetype = 'regular'

```

---

_[View the full topic](https://meta.discourse.org/t/data-explorer-query-to-return-certain-post-notices/271090)._
