Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Please help: SELECT with calc
NNOOR wrote:
>
> I have a few columns in a table (DAY_1, DAY_2...DAY_14). I want to
> sum all of these columns accross all of the records. i.e. what is
> the total of all numbers in all DAY_x fields for a given WHERE
> criteria. It should be pretty simple but I can't figure it out.
>
What about
select sum(nvl(day_1,0)+nvl(day_2,0)+nvl(day_3,0))
from xxx.yyy
where ...
sum ... group function to calculate sum of all records nvl ... if there is no value (e.g. day_2 is null) use 0
Hope this helps.
Peter
> I tried following but both gave different and wrong results.
>
> (assuming columns are DAY_1, DAY_2 and DAY_3)
>
> SELECT (DAY_1 + DAY_2 + DAY_3) from xxx.yyy
> where ...
>
> AND
>
> SELECT (((DAY_1) + DAY_2) + DAY_3) from ...
> where ...
>
> Thanks very much for your help!!!
>
> Regards,
> Nasir (nnoor_at_cris.com)
Received on Fri Oct 31 1997 - 00:00:00 CST