Select
Case When field2 in (value1, value2) Then field1 Else 0 End,
Case When field2 in (value3, value4) Then field1 Else 0 End
From table1
Where tmp.key = key
And field2 in (value1, value2, value3, value4);
Tom
"ikke666" wrote in message
>
> I've got a grouping problem.
> I want to create 2 columns with the sum of field1 where the sum of the
> first column is of the field1 where field2 equals value1 or value2 and
> the second sum of field1 where field2 equals equals value3 or value4.
> I've got a solution but the performance is so poor because it is with a
> subquery:
>
> select sum(field1)
> ( select sum(tmp.field2)
> from table1 as tmp
> where tmp.key = key
> and field2 = value3
> or field2 = value4
> )
> from table1
> where field2 = value1
> or field2 = value2
>
> Has anyone a more potent solution to my problem???? >> Stay informed about: sql query question