Re: [HACKERS] Using aggregate in HAVING
От | Mike Mascari |
---|---|
Тема | Re: [HACKERS] Using aggregate in HAVING |
Дата | |
Msg-id | 386A6C58.C453600D@mascari.com обсуждение исходный текст |
Ответ на | Using aggregate in HAVING (Bruce Momjian <pgman@candle.pha.pa.us>) |
Ответы |
Re: [HACKERS] Using aggregate in HAVING
|
Список | pgsql-hackers |
Bruce Momjian wrote: > > How would I get all friends greater than the average age? > > CREATE TABLE friends ( > firstname CHAR(15), > lastname CHAR(20), > age INTEGER) > > SELECT firstname, lastname > FROM friends > HAVING age >= AVG(age) > > ERROR: Attribute friends.firstname must be GROUPed or used in an > aggregate function > > This fails too: > > SELECT firstname, lastname > FROM friends > WHERE age >= AVG(age) > > ERROR: Aggregates not allowed in WHERE clause > > This fails. I am stumped. Without using subselects? With subselects you could also do: SELECT firstname, lastname FROM friends WHERE age >= (SELECT AVG(age) FROM friends); Are you writing the chapter on aggregates? Mike Mascari
В списке pgsql-hackers по дате отправления: