Subject RE: [firebird-support] Conditional grouping?
Author Rick Debay
Thanks, I'll give this a try tomorrow.
I was thinking of using CASE, but my only thought in that direction was
to put it inside the SUM function somehow.

Rick

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Ivan Prenosil
Sent: Thursday, July 28, 2005 3:25 PM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Conditional grouping?

> I'm probably being dense, but I can't figure out how to do a
> conditional grouping.
> I need to sum quantities based on these columns (GPI, TEE, UNIT_DOSE),

> but also on an additional column (DOSE_SIZE) if one of first set
> (UNIT_DOSE) meets certain criteria.
>
> GROUP BY
> GPI, TEE, UNIT_DOSE, (IF UNIT_DOSE IN ('X','U') DOSE_SIZE)
>
> The only thing I could come up with is to do two queries, union them,
> and then sum that.

SELECT CASE WHEN UNIT_DOSE IN ('X','U') THEN DOSE_SIZE ELSE NULL END,
...
GROUP BY GPI, TEE, UNIT_DOSE, 1

Ivan



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://firebird.sourceforge.net and click the Resources item on
the main (top) menu. Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Yahoo! Groups Links