How to add positive and negative numbers in a single column and output them to two different columns

Showing Answers 1 - 12 of 12 Answers

Gurwinder Singh Saini

  • Feb 15th, 2007
 

pn is table having +ve and -ve values SQL> select * from pn ; NUM---------- 1 2 3 -1 -4 -56 rows selected.SQL> -----Seperate positive & negative valuseSQL> SELECT (CASE WHEN num<0 THEN num ELSE 0 END) neg, (CASE WHEN num>0 THEN num ELSE 0 END) pos FROM pn ; NEG POS---------- ---------- 0 1 0 2 0 3 -1 0 -4 0 -5 06 rows selected.

  Was this answer useful?  Yes

svj2000

  • Mar 16th, 2007
 

table temp with a column num of type number

select

sum(case when num > 0 then num else null end) pos,

sum(case when num < 0 then num else null end) neg

from temp

  Was this answer useful?  Yes

Rina_S

  • Dec 24th, 2007
 

E.g. SELECT * FROM TAB1;

 COL1 C
----- -
   -1 A
   -2 A
    1 B
    2 B
SELECT DECODE(SIGN(COL1), -1, col1, null) A, DECODE(SIGN(COL1), 1, COL1, NULL) B FROM TAB1;

    A          B
----- ----------
   -1
   -2
               1
               2

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions