# SQL-query voor laatst aangemaakte gebruikers van de afgelopen 30 dagen

**URL:** https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209
**Category:** Support
**Created:** [15 augustus 2022 om 14:52 UTC](https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209 "2022-08-15T14:52:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AquaL1te](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aqual1te/32/201966_2.png) [@AquaL1te](https://meta.discourse.org/u/AquaL1te)
#### Post date: [15 augustus 2022 om 14:52 UTC](https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209/1 "2022-08-15T14:52:21Z")

</div>

How to get all users that signed up in the last 30 days? I suppose I need some builtin SQL function to generate this date format and then do -30 days. I’ve tried a few examples from the Interwebz, such as [this](https://meta.discourse.org/t/how-to-measure-active-users/74574/5), but I get a syntax error.

```sql
WITH query_period AS (
SELECT
date_trunc('month', CURRENT_DATE) - INTERVAL '1 months' as period_start,
date_trunc('month', CURRENT_DATE) - INTERVAL '1 months' + INTERVAL '1 month' - INTERVAL '1 second' as period_end
),

SELECT username FROM users WHERE created_at >= period_start AND created_at <= period_end

```

```plaintext
PG::SyntaxError: ERROR: syntax error at or near "SELECT"
LINE 13: SELECT username FROM users WHERE created_at >= period_start ...

```

Does anyone see what I’m missing here? Or could this be done much better as a whole?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [15 augustus 2022 om 14:56 UTC](https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209/2 "2022-08-15T14:56:26Z")

</div>

You might have a look in [Topics tagged data-explorer](https://meta.discourse.org/tag/data-explorer) or [Discourse Data Explorer](https://meta.discourse.org/t/discourse-data-explorer/32566) or [What cool data explorer queries have you come up with?](https://meta.discourse.org/t/what-cool-data-explorer-queries-have-you-come-up-with/43516) for some examples.

---

<div class="post-metadata">

### Author: ![AquaL1te](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aqual1te/32/201966_2.png) [@AquaL1te](https://meta.discourse.org/u/AquaL1te)
#### Post date: [15 augustus 2022 om 15:19 UTC](https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209/3 "2022-08-15T15:19:54Z")

</div>

Got it.

```sql
SELECT username FROM users WHERE created_at >= CURRENT_TIMESTAMP - INTERVAL '30 days' AND staged = false

```

---

<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: [14 september 2022 om 15:20 UTC](https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209/4 "2022-09-14T15:20:43Z")

</div>

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