Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: sql help --urgent

Re: sql help --urgent

From: Rangachari Sundar <sundar_at_focusite.com>
Date: Sat, 21 Jul 2001 03:26:46 -0700
Message-ID: <F001.00350A9E.20010721033022@fatcity.com>

Hi,

Select a, decode(sign(a), -1, 0, a-1) from <Table Name>

For summing up : sum(decode(sign(a), -1, 0, a-1))

Hope this helps

Bye
Sundar

Ravindra Basavaraja wrote:

> 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 0
> .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
> positive numbers
>
> 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: Rangachari Sundar
  INET: sundar_at_focusite.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 Sat Jul 21 2001 - 05:26:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US