Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Case statement in Group by ?
sonukapoor_at_gmail.com wrote:
> Here is what I am trying:
>
> Select
> MAX(c1),
> sum(qty),
> c2
> from
> t1
> where
> c1 = 'test'
> Having
> (
> SUM(qty) > @TotalItemsParam
> )
> AND
> (
> c4 = @somevar and @condition = 'true' <-- wants me to have a group
> by, but I do not want
> )
> group by
> case when @condition = 'true' then c4 else c2 end
>
>
> The C4 in the having wants me to include the group by, which I do not
> want. Ideally I would want to include the AND statement and group by
> only if some condition is true. I hope that makes sense. Please suggest
> me.
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
Your HAVING clause has not in the correct place.
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace 'x' with 'u' to respond)Received on Wed Feb 09 2005 - 20:24:42 CST