Re: A GROUP BY question

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: stan <stanb(at)panix(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: A GROUP BY question
Date: 2019-08-13 14:35:05
Message-ID: 9A246E87-E81A-46FB-A69D-021698A9B731@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On 13 Aug 2019, at 15:19, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Tuesday, August 13, 2019, Alban Hertroys <haramrae(at)gmail(dot)com> wrote:
>
> > On 13 Aug 2019, at 13:10, stan <stanb(at)panix(dot)com> wrote:
> >
> > select
> > project.proj_no ,
>
> Removed columns that get in the way of your desired result. You can’t have both details and the sum over them in a meaningful way.
>
> Sure you can, at least generally, with Window Functions/Expressions (i.e., OVER)

That’s why I added “in a meaningful way” ;)

Repeating the same SUM-result on every line in a group is not what I’d call a meaningful result; the SUM has no bearing on the detailed line and leads to the kind of mistakes I already mentioned.
(For the record; I do this kind of grouping in a hierarchical database regularly, but there the grouped SUM is at a different level in the hierarchy and I consider it thus sufficiently separated from the detail rows.)

Besides, I figured the OP was already struggling with the query syntax, adding window functions into the mix didn’t seem a good idea in the context. Possible?, sure, desirable?, I would say not.

Alban Hertroys
--
There is always an exception to always.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Luca Ferrari 2019-08-13 14:48:43 Re: Question on pgwatch
Previous Message Souvik Bhattacherjee 2019-08-13 13:34:35 Re: Bulk Inserts