Lets say i have table with that looks something like this:
-3000 -------------------- 00162Q205
4000 -------------------- 00162Q205
6000 -------------------- 00162Q205
8000 -------------------- 00162Q205
10000-------------------- 33733B100
-2900 -------------------- 33733B100
1000-------------------- 33733B100
8000 -------------------- 33733B100
7000-------------------- 464286178
-1200 -------------------- 464286178
1000-------------------- 464286178
1000 -------------------- 464286178
How can I make it so I get the results:
21000------------------------00162Q205
21900-----------------------33733B100
10200------------------------4642861
Basically I would like to sum each the absolute value for each distinct cusip_nbr and return a result that plots each cusip_nbr and its respective absolute value sum. (Only three distinct cusip_nbr 's are shown here but i have hundreds of them, each with a cns_amt that needs to be summed)
You can use ABS()
to get the absolute value, and SUM()
:
SELECT cusip_nbr, SUM(ABS(cns_amt)) 'total_amt'
FROM Table
GROUP BY cusip_nbr
Demo: SQL Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With