Re: Query help

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: John W Higgins <wishdev(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query help
Date: 2019-01-01 22:10:17
Message-ID: 59b4791a-119e-c61a-c879-4687eb02afcb@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/1/19 12:05 PM, David G. Johnston wrote:
> On Tuesday, January 1, 2019, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)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.

Hmm, guess I should spend more time reading the SELECT docs:)

>
> David J.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message chiru r 2019-01-02 00:18:17 Re: Relocatable Binaries (RPMs) : custom installation path for PostgreSQL
Previous Message Brent Wood 2019-01-01 20:53:45 Re: Relocatable Binaries (RPMs) : custom installation path for PostgreSQL