In SQL Server
you can do sum(field1) to get the sum of all fields that match the groupby clause.
But I need to have the fields subtracted, not summed.
Is there something like subtract(field1) that I can use in stead of sum(field1) ?
For example, table1 has this content :
name field1
A 1
A 2
B 4
Query:
select name, sum(field1), subtract(field1)
from table1
group by name
would give me:
A 3 -1
B 4 4
I hope my question is clear.
EDIT :
there is also a sortfield that i can use. This makes sure that values 1 and 2 will always lead to -1 an not to 1.
What I need is all values for A subtracted, in my example 1 - 2 = -1
EDIT2 : if the A-group has values 1, 2, 3, 4 the result must be 1 - 2 - 3 - 4 = -8