Re: how to effectively SELECT new "customers" - Mailing list pgsql-sql

From Jan Ostrochovsky
Subject Re: how to effectively SELECT new "customers"
Date
Msg-id 2042881838.607913.1393690147570.JavaMail.root@mobiletech.sk
Whole thread Raw
In response to Re: how to effectively SELECT new "customers"  (David Johnston <polobo@yahoo.com>)
Responses Re: how to effectively SELECT new "customers"  (David Johnston <polobo@yahoo.com>)
List pgsql-sql
Without incorporating additional meta-data about the purchases onto the
customer table the most basic solution would be:

SELECT DISTINCT customer_id FROM products WHERE date > (now() - '12
months'::interval)
EXCEPT
SELECT DISTINCT customer_id FROM products WHERE date <= (now() - '12
months'::interval)

---

Another solution:
WHERE ... >12 AND NOT EXISTS (SELECT ... WHERE <= 12)

David J.
subsidiary matter: in what circumstances is better to use EXCEPT and in what NOT EXISTS?

are those equivalents? tried to google their comparison, but no relevant results found for PostgreSQL

pgsql-sql by date:

Previous
From: Jan Ostrochovsky
Date:
Subject: Re: how to effectively SELECT new "customers"
Next
From: David Johnston
Date:
Subject: Re: how to effectively SELECT new "customers"