Re: Group By with condition - Mailing list pgsql-sql

From Steve Midgley
Subject Re: Group By with condition
Date
Msg-id CAJexoS+xfmkmZT+-YgYaN4Y+2BpnnMBkLmStvJduLHmsh_c00w@mail.gmail.com
Whole thread Raw
In response to Group By with condition  (JORGE MALDONADO <jorgemal1960@gmail.com>)
Responses Re: Group By with condition  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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@gmail.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

pgsql-sql by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Group By with condition
Next
From: "David G. Johnston"
Date:
Subject: Re: Group By with condition