Re: Aggregate functions not allowed in WHERE clause - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Aggregate functions not allowed in WHERE clause
Date
Msg-id 20060613023817.GA3333@winnie.fuhr.org
Whole thread Raw
In response to Aggregate functions not allowed in WHERE clause  (Ricardo Naranjo Faccini <gramo.gnu@gmail.com>)
Responses Re: Aggregate functions not allowed in WHERE clause
List pgsql-general
On Mon, Jun 12, 2006 at 09:00:33PM -0500, Ricardo Naranjo Faccini wrote:
> SELECT claim_id
> FROM logs
> WHERE (
>     sum(logs.invoices) > 0
>     OR
>     sum(logs.payments) > 0
> )
> GROUP BY claim_id
>
> But Postgres claims "Aggregate functions not allowed in WHERE clause"

I think you're looking for HAVING.  Does the following do what you
want?

SELECT claim_id
FROM logs
GROUP BY claim_id
HAVING sum(invoices) > 0 OR sum(payments) > 0;

--
Michael Fuhr

pgsql-general by date:

Previous
From: Ricardo Naranjo Faccini
Date:
Subject: Aggregate functions not allowed in WHERE clause
Next
From: Christopher Browne
Date:
Subject: Re: Aggregate functions not allowed in WHERE clause