On Thu, Jul 01, 2004 at 10:56:29 +0200,
peter pilsl <pilsl@goldfisch.at> wrote:
>
>
> I have a question to sql and dont know exactely if this is the right
> place to ask. If not I would be glad if anyone could point me to the
> correct group/list/resource. Thnx.
>
> I want to perform a sum-operation in a group by - query and want to
> specify additionaly conditions when to sum.
>
> like: having a table with colums x,y,z
>
> select x,sum(y only if z is 'val1'),sum(y only if z is 'val2') from
> table group by x;
You can use CASE to do this. The CASE function goes inside the sum
function call similar to what you sketched out above.