Active users in the last 30 days
select username
from users
where last_posted_at > current_timestamp - interval '30' day
select username
from users
where last_posted_at > current_timestamp - interval '30' day
How would you adjust this with parameters so that previous months can also be checked? Eg: read between 62 and 31 days ago (or similar)?
I haven’t figured out a “between” way of doing this, but using “params” can provide a selectable “back to”
-- [params]
-- int :interval = 30
select username
from users
where last_posted_at > current_timestamp - interval ':interval' day
should be able to do something like this (starting where @Mittineague left off):
-- [params]
-- int :until_days_ago = 30
-- int :since_days_ago = 60
select username
from users
where last_posted_at > current_timestamp - interval ':since_days_ago' day
and last_posted_at < current_timestamp - interval ':until_days_ago' day