Re: DONT_CARE Aggregate - Mailing list pgsql-general

From Chris Curvey
Subject Re: DONT_CARE Aggregate
Date
Msg-id CADfwSsBzN3LcJHi_WjiuHTfQQ56GAuO-6rM5M2-bX38TXwz6aQ@mail.gmail.com
Whole thread Raw
In response to Re: DONT_CARE Aggregate  (Robert James <srobertjames@gmail.com>)
List pgsql-general

On Thu, Dec 20, 2012 at 12:00 PM, Robert James <srobertjames@gmail.com> wrote:
I see.  What if I need to do this along with an Aggregate Query.  Eg
something like:

SELECT x,y,z, MAX(a), MAX(b), DONT_CARE_AS_LONG_AS_NOT_NULL(c),
DONT_CAR_AS_LONG_AS_P_IS_TRUE(d,p)
...
GROUP BY x,y,z


ah, I get what you're trying to do.  If you truly don't care about the value of C, then just use MIN() or MAX().  

for the conditional part, use a CASE statement, along with MAX or MIN, like this:

SELECT MIN(CASE WHEN P=TRUE THEN D ELSE NULL END)

Because MIN() and MAX() ignore NULL values.  (Except for the special case where all the values are null.)


--
e-Mail is the equivalent of a postcard written in pencil.  This message may not have been sent by me, or intended for you.  It may have been read or even modified while in transit.  e-Mail disclaimers have the same force in law as a note passed in study hall.  If your corporate attorney says that you need an disclaimer in your signature, you need a new corporate attorney.

pgsql-general by date:

Previous
From: Robert James
Date:
Subject: Re: DONT_CARE Aggregate
Next
From: Marti Raudsepp
Date:
Subject: Re: DONT_CARE Aggregate