sql - Where date difference between now and max date value is greater than X -


i want return result set (from postgres database) containing clients last payment date more x number of days ago.

this have list of clients , last payment date:

  select usermaster.userid, date_trunc('days', now()-max(paymentdate)) last_payment   usermaster, paymentdetail    usermaster.userid=paymentdetail.userid   group usermaster.userid; 

i limit condition: ... , last_payment > 100 days

this should trick

edit -

select *  (select usermaster.userid, date_trunc('days', now()-max(paymentdate))           last_payment usermaster, paymentdetail  usermaster.userid=paymentdetail.userid group usermaster.userid ) temptab last_payment>100; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -