I have a group by clause in a sql statement and need to use an aggregate function to minus all the values in each group instead of adding like the Sum() function.
i.e.
SELECT Sum(A)
FROM (
SELECT 2 AS A
UNION
SELECT 1) AS t1
..so will evaluate 2+1 and return 3.
I need some way of doing 2-1 to return 1.
Hope this makes sense. Only way I can think of doing this would be to use CLR integration to make my own aggregate function.
Any other ideas?