Subject Re: Conditional grouping?
Author Antonis Tsourinakis
In such conditions I usualy use this (stolen from mine source)

SELECT H.DEPDATE, M.MESO_NAME, I.ITIN_NAME,
CASE C.OPTIONDATE
WHEN '' THEN 1
ELSE 2
end AS KIND, COUNT(*)
FROM CABINMAIN C
JOIN CALENHEAD H ON H.CALHEAD_ID = C.CALHEAD_ID
JOIN MEAN M ON H.MEAN_ID = M.MEAN_ID
JOIN ITINNAMES I ON H.ITNAME_ID = I.ITNAME_ID
GROUP BY 1, 2, 3, 4
ORDER BY 1

--- In firebird-support@yahoogroups.com, "Rick Debay" <rdebay@r...> wrote:
> 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.
>
> Rick DeBay