Re: Query help - Mailing list pgsql-general

From David G. Johnston
Subject Re: Query help
Date
Msg-id CAKFQuwZ=YT0AaNR94er-LmVb_4Oj0q_KyX=eUsD7usWEAg00SQ@mail.gmail.com
Whole thread Raw
In response to Re: Query help  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Query help  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
On Tuesday, January 1, 2019, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 1/1/19 11:26 AM, John W Higgins wrote:
with accounts_over_total as (
select accountid from transactions where sum(amount) >= 50 group by accountid)

Unfortunately there is a hitch in the above:(

select p_item_no from projection where sum(qty) > 100 group by(p_item_no);
ERROR:  aggregate functions are not allowed in WHERE

Which is where the HAVING clause comes in.  It filters out groups based on an expression containing an aggregate function.

David J. 

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Query help
Next
From: Brent Wood
Date:
Subject: Re: Relocatable Binaries (RPMs) : custom installation path forPostgreSQL