Re: Aggregates not allowed in WHERE clause? - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Aggregates not allowed in WHERE clause?
Date
Msg-id 20041216053719.GA43376@winnie.fuhr.org
Whole thread Raw
In response to Aggregates not allowed in WHERE clause?  (Frans <fransgunawan@gmail.com>)
List pgsql-general
On Thu, Dec 16, 2004 at 12:02:34PM +0700, Frans wrote:

> I try to use : select name, sum(quantity) from info where
> sum(quantity)>20 group by name;
> This yields the message: 'Aggregates not allowed in WHERE clause'.

For aggregates use HAVING, not WHERE:

SELECT name, SUM(quantity)
FROM info
GROUP BY name
HAVING SUM(quantity) > 20;

http://www.postgresql.org/docs/7.4/static/tutorial-agg.html
http://www.postgresql.org/docs/7.4/static/queries-table-expressions.html#QUERIES-GROUP
http://www.postgresql.org/docs/7.4/static/sql-select.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: bytea internal encoding
Next
From: Mickael Remond
Date:
Subject: Re: Insert do not work in my case