1

What I am trying to accomplish is to find all the customers who have sales in the past but have not purchased from us in the last 2 years (SYSDATE - INTERVAL '2' YEAR)

Here is my code currently.

select invc.company
 , invc.customer_id
 , to_char(invc.invdate, 'mm/dd/yyyy') as date
 , invc.name
 , invc.address1
 , invc.address2
 , invc.city
 , invc.state
 , invc.zip_code
 , invc.country
 , invc.region_code
 , invc.site
 , sum(invc.sales) as SlsAmnt
from ifsinfo.hb_invoicing_all invc
where **THIS IS THE PART IM STUCK AT**
group by invc.company
           , invc.customer_id
           , invc.creation_date
           , invc.name
           , invc.address1
           , invc.address2
           , invc.city
           , invc.state
           , invc.zip_code
           , invc.country
           , invc.region_code
           , invc.site

I am basically looking for a query that will return a list of customers who haven't purchased from us in 2 years or more.

SUM(SALES) = 0 within last 2 years+

2
  • 1
    Is it possible to have Sales with a zero or less amount? If not can't you just ensure their ID is not in the sales table with a date more recent than 2 years ago?
    – Dave
    Commented Sep 29, 2015 at 21:49
  • It is NOT possible. That is a great point Dave. Thank you for that input!
    – Hector
    Commented Sep 29, 2015 at 21:54

1 Answer 1

2

No sales in the last two years means:

having max(invc.invdate) < (SYSDATE - INTERVAL '2' YEAR) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.