Re: Aggregate functions not allowed in WHERE clause

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Aggregate functions not allowed in WHERE clause
Дата
Msg-id 20060613023817.GA3333@winnie.fuhr.org
обсуждение исходный текст
Ответ на Aggregate functions not allowed in WHERE clause  (Ricardo Naranjo Faccini <gramo.gnu@gmail.com>)
Ответы Re: Aggregate functions not allowed in WHERE clause  (pradeep singh <lets_begin_with_me@yahoo.com>)
Список pgsql-general
On Mon, Jun 12, 2006 at 09:00:33PM -0500, Ricardo Naranjo Faccini wrote:
> SELECT claim_id
> FROM logs
> WHERE (
>     sum(logs.invoices) > 0
>     OR
>     sum(logs.payments) > 0
> )
> GROUP BY claim_id
>
> But Postgres claims "Aggregate functions not allowed in WHERE clause"

I think you're looking for HAVING.  Does the following do what you
want?

SELECT claim_id
FROM logs
GROUP BY claim_id
HAVING sum(invoices) > 0 OR sum(payments) > 0;

--
Michael Fuhr

В списке pgsql-general по дате отправления:

Предыдущее
От: Ricardo Naranjo Faccini
Дата:
Сообщение: Aggregate functions not allowed in WHERE clause
Следующее
От: Christopher Browne
Дата:
Сообщение: Re: Aggregate functions not allowed in WHERE clause