Using aggregate in HAVING - Mailing list pgsql-hackers

From Bruce Momjian
Subject Using aggregate in HAVING
Date
Msg-id 199912291951.OAA08646@candle.pha.pa.us
Whole thread Raw
List pgsql-hackers
How would I get all friends greater than the average age?
CREATE TABLE friends (     firstname CHAR(15),     lastname CHAR(20),     age INTEGER)
SELECT firstname, lastnameFROM friendsHAVING age >= AVG(age)ERROR:  Attribute friends.firstname must be GROUPed or used
inanaggregate function
 

This fails too:
SELECT firstname, lastnameFROM friendsWHERE age >= AVG(age)ERROR:  Aggregates not allowed in WHERE clause

This fails.  I am stumped.

--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: "svn"
Date:
Subject: revoke/grant rights issue
Next
From: Mike Mascari
Date:
Subject: Re: [HACKERS] Using aggregate in HAVING