Re: Group By with condition

From: Steve Midgley <science(at)misuse(dot)org>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Group By with condition
Date: 2015-05-21 22:29:20
Message-ID: CAJexoS+xfmkmZT+-YgYaN4Y+2BpnnMBkLmStvJduLHmsh_c00w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm not totally clear on your requirement but would the HAVING keyword
solve the problem? That's kind of like a WHERE but in the group by phase of
the query..

SELECT fld1, fld2, fld3, fld4 FROM tblTable1
INNER JOIN ............
GROUP BY fld1, fld2, fld3, fld4
HAVING fld4='TL'

On Thu, May 21, 2015 at 3:14 PM, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
wrote:

> Let´s suppose I have the following query:
>
> SELECT fld1, fld2, fld3, fld4 FROM tblTable1
> INNER JOIN ............
> GROUP BY fld1, fld2, fld3, fld4
>
> What I need is to group by "fld4" if and only if its value is "TL". If its
> value is different than "TL" then no grouping should be performed on this
> field.
>
> I will very much appreciate ypur feedback.
>
> Respectfully,
> Jorge Maldonado
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2015-05-21 23:54:42 Re: Group By with condition
Previous Message JORGE MALDONADO 2015-05-21 22:14:41 Group By with condition