I want to return a result set (from postgres database) containing clients whose last payment date was more than X number of days ago.
This is what I have currently to get a list of all clients and their last payment date:
select usermaster.userid, date_trunc('days', now()-max(paymentdate)) as last_payment
from usermaster, paymentdetail
where usermaster.userid=paymentdetail.userid
group by usermaster.userid;
I would like to limit with an extra where condition: where ... and last_payment > 100 days