Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: sql help --urgent
decode(sign(a), -1, 0, a)
Ron Thomas
Hypercom, Inc
rthomas_at_hypercom.com
"I'm too sexy for my code." - Awk Sed Fred
ravindra_at_sent ica.com To: ORACLE-L_at_fatcity.com Sent by: cc: root_at_fatcity. Subject: sql help --urgent com 07/20/01 12:40 PM Please respond to ORACLE-L
I have a table with a number column(Col A).I want to display A-1.There could
be some negative values in
this A-1 column.But I want to display 0 whereever negative value appears.I
can use the ROUND(A-1) but this
will round the other positive value to the next positve integer which I
don't want to happen.
select a,a-1,round(a-1) from t;
A A-1 ROUND(A-1)
----- ---------- ----------
3 2 2 1 0 0positive numbers
.6 -.4 0
.8 -.2 0
6 5 5 3.5 2.5 3 .69 -.31 0 2.7 1.7 2 sum 10.29------>this value is the sum of all the negative and
I want the o/p to be like this.The decimal numbers should not be rounded off to the next number.
select a,a-1,round(a-1) from t;
A A-1 MY REQUIREMENT
----- ---------- ----------
3 2 2 1 0 0
.6 -.4 0
.8 -.2 0
6 5 5 3.5 2.5 2.5 .69 -.31 0 2.7 1.7 1.7 Sum 11.2(My REQUIREMENT)
My requirement is to compute the sum of the columns for exact value i.e I want the sum of only the positive numbers(negative numbers should not be counted for the sum that's why I want to display 0 for negative value as the sum function adds all the positive and negative numbers)
How can I do this
Thanks
Ravindra
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Ravindra Basavaraja INET: ravindra_at_sentica.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Ron Thomas INET: rthomas_at_hypercom.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Fri Jul 20 2001 - 15:26:14 CDT
![]() |
![]() |