Re: [SQL] Simple aggregate query brain fart

2010-03-18 Thread Mark Fenbers
Thanks, Joe and Tom.  You cleared the webs out of my brain.  I used HAVING before, but not lately and I got rusty. Mark Tom Lane wrote: Mark Fenbers writes: I want to do: SELECT id, count(*) FROM mytable WHERE count(*) > 2 GROUP BY id; But this doesn't work b

Re: [SQL] Simple aggregate query brain fart

2010-03-18 Thread Tom Lane
Mark Fenbers 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

Re: [SQL] Simple aggregate query brain fart

2010-03-18 Thread Plugge, Joe R.
sql@postgresql.org Subject: [SQL] Simple aggregate query brain fart 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. So I modified it to: SELECT id, count(*) AS cnt FROM mytab

[SQL] Simple aggregate query brain fart

2010-03-18 Thread Mark Fenbers
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. So I modified it to: SELECT id, count(*) AS cnt FROM mytable WHERE cnt > 2 GROUP BY id; But Pg still complains (that column cnt