Re: DONT_CARE Aggregate

From: Chris Curvey <chris(at)chriscurvey(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>, Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: DONT_CARE Aggregate
Date: 2012-12-20 17:11:26
Message-ID: CADfwSsBzN3LcJHi_WjiuHTfQQ56GAuO-6rM5M2-bX38TXwz6aQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 20, 2012 at 12:00 PM, Robert James <srobertjames(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marti Raudsepp 2012-12-20 17:24:35 Re: DONT_CARE Aggregate
Previous Message Robert James 2012-12-20 17:00:13 Re: DONT_CARE Aggregate