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, but I get a syntax error.
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 ...
Does anyone see what I’m missing here? Or could this be done much better as a whole?