Mark Fenbers <mark.fenb...@noaa.gov> writes:
> I want to do:
> SELECT id, count(*) FROM mytable WHERE count(*) > 2 GROUP BY id;

> But this doesn't work because Pg won't allow aggregate functions in a 
> where clause.

Use HAVING, not WHERE.  The way you are trying to write the query is
meaningless because WHERE filters rows before grouping/aggregation.
HAVING filters afterwards, which is when it makes sense to put a
condition on count(*).

                        regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to