# Consulta SQL para los últimos usuarios creados en los últimos 30 días

**URL:** <https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209>\
**Category:** Product Support\
**Created:** [15 Agosto, 2022 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:** 1\
**Showing post:** 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 Agosto, 2022 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>

¿Cómo obtengo todos los usuarios que se registraron en los últimos 30 días? Supongo que necesito alguna función SQL incorporada para generar este formato de fecha y luego restar 30 días. He probado algunos ejemplos de Internet, como [este](https://meta.discourse.org/t/how-to-measure-active-users/74574/5?u=aqual1te), pero obtengo un error de sintaxis.

```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 ...

```

¿Alguien ve lo que me falta? ¿O se podría hacer mucho mejor en general?

---

_[View the full topic](https://meta.discourse.org/t/sql-query-for-last-created-users-of-the-past-30-days/236209)._
