Re: Aggregates not allowed in WHERE clause?

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Aggregates not allowed in WHERE clause?
Дата
Msg-id 20041216053719.GA43376@winnie.fuhr.org
обсуждение исходный текст
Ответ на Aggregates not allowed in WHERE clause?  (Frans <fransgunawan@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: bytea internal encoding
Следующее
От: Mickael Remond
Дата:
Сообщение: Re: Insert do not work in my case