From: Adrian Klaver <adrian.klaver@aklaver.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: John W Higgins <wishdev@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Query help
Date: Tue, 1 Jan 2019 14:10:17 -0800
Message-ID: <59b4791a-119e-c61a-c879-4687eb02afcb@aklaver.com> (raw)
In-Reply-To: <CAKFQuwZ=YT0AaNR94er-LmVb_4Oj0q_KyX=eUsD7usWEAg00SQ@mail.gmail.com>
References: <CAFw6=U0v9CHqtfN+g6DriVGpR5veS-oTz7t16c4j+0q70ifLEg@mail.gmail.com>
<CAPhAwGzA3ZOcfkeXBH7t-H5xBU4PuPAWwpfKLEGotSyQp58dkw@mail.gmail.com>
<073395bd-912c-2e4e-7892-58aa86283c52@aklaver.com>
<CAKFQuwZ=YT0AaNR94er-LmVb_4Oj0q_KyX=eUsD7usWEAg00SQ@mail.gmail.com>
On 1/1/19 12:05 PM, David G. Johnston wrote:
> On Tuesday, January 1, 2019, Adrian Klaver <adrian.klaver@aklaver.com
> <mailto: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.
Hmm, guess I should spend more time reading the SELECT docs:)
>
> David J.
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, david.g.johnston@gmail.com, wishdev@gmail.com
Subject: Re: Query help
In-Reply-To: <59b4791a-119e-c61a-c879-4687eb02afcb@aklaver.com>
References: <CAFw6=U0v9CHqtfN+g6DriVGpR5veS-oTz7t16c4j+0q70ifLEg@mail.gmail.com> <CAPhAwGzA3ZOcfkeXBH7t-H5xBU4PuPAWwpfKLEGotSyQp58dkw@mail.gmail.com> <073395bd-912c-2e4e-7892-58aa86283c52@aklaver.com> <CAKFQuwZ=YT0AaNR94er-LmVb_4Oj0q_KyX=eUsD7usWEAg00SQ@mail.gmail.com> <59b4791a-119e-c61a-c879-4687eb02afcb@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox