What is the counterpart for SUM() in SQL Server?
<p>In <code>SQL Server</code> you can do sum(field1) to get the sum of all fields that match the groupby clause.<br>
But I need to have the fields subtracted, not summed.<br>
Is there something like subtract(field1) that I can use in stead of sum(field1) ?</p>

<p>For example, table1 has this content :  </p>

<pre><code>name field1  
A 1  
A 2  
B 4  
</code></pre>

<p>Query:</p>

<pre><code>select name, sum(field1), subtract(field1)  
from table1  
group by name  
</code></pre>

<p>would give me:</p>

<pre><code>A 3 -1  
B 4 4 
</code></pre>

<p>I hope my question is clear.</p>

<p>EDIT :</p>

<p>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.</p>

<p>What I need is all values for A subtracted, in my example 1 - 2 = -1</p>

<p>EDIT2 :
if the A-group has values 1, 2, 3, 4 the result must be 1 - 2 - 3 - 4 = -8</p>