Reputation: 33
I have both positive and negative numbers (money) in a column and need to:
SQL is not my trade as you probably notice but we've solved most other issues but this one so any help is appriciated. Keep in mind my skill level is very low
Upvotes: 3
Views: 16107
Reputation: 7823
Try one (or more) of these
SELECT SUM(moneyColumn) FROM MyTable
SELECT SUM(ABS(moneyColumn)) FROM MyTable
SELECT ABS(SUM(moneyColumn)) FROM MyTable
Upvotes: 1
Reputation: 245459
You will have to use a combination of the sum
and abs
aggregate functions in SQL. Since you want the absolute value of the sum, the sum
function will need to be called inside the call to abs
:
select abs(sum(columnName)) from table
That should work for both SQL Server, MySQL, and Oracle.
Upvotes: 11