Re: how to effectively SELECT new "customers"

From: Jan Ostrochovsky <ostrochovsky(at)mobiletech(dot)sk>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to effectively SELECT new "customers"
Date: 2014-03-01 16:09:07
Message-ID: 2042881838.607913.1393690147570.JavaMail.root@mobiletech.sk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David Johnston 2014-03-02 04:08:39 Re: how to effectively SELECT new "customers"
Previous Message Jan Ostrochovsky 2014-03-01 14:24:47 Re: how to effectively SELECT new "customers"