SELECT date, address, balance, balance_usd, currency FROM
terra.daily_balances
WHERE address IN
-- this achieves the condition for being active in the last 90 days (operationalized as having more than 0 USD in total balance)
(SELECT address FROM
terra.daily_balances
WHERE date_trunc('day', date) >= date_trunc('day', current_date) - 90 AND balance_usd != 0
GROUP BY address)
AND
-- this only retreieves the entries within 90 days
date_trunc('day', date) >= date_trunc('day', current_date) - 90
AND
balance_usd != 0