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?