Query SQL per gli ultimi utenti creati negli ultimi 30 giorni

Come ottenere tutti gli utenti registrati negli ultimi 30 giorni? Suppongo che avrò bisogno di una funzione SQL integrata per generare questo formato di data e poi sottrarre 30 giorni. Ho provato alcuni esempi dal web, come questo, ma ottengo un errore di sintassi.

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
PG::SyntaxError: ERROR:  syntax error at or near "SELECT"
LINE 13: SELECT username FROM users WHERE created_at >= period_start ...

Qualcuno vede cosa mi manca? O si potrebbe fare molto meglio nel complesso?

Potresti dare un’occhiata a Topics tagged data-explorer o Discourse Data Explorer o Quali fantastiche query di Data Explorer ti sono venute in mente? per alcuni esempi.

1 Mi Piace

Capito.

SELECT username FROM users WHERE created_at >= CURRENT_TIMESTAMP - INTERVAL '30 days' AND staged = false
2 Mi Piace

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