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.
>
> 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)
Hi Nasir,
I think that there's a bad tabel layout in your db.
You want to save a value for each day of the month and created a record with a field for every day and now you want to summ up the values so that you've the total for each month, right?
In this case I would layout my table like this:
seq_value number day date value whatever value you've got
To make the total for a certain period you've got to use
Select
Sum(value) as total
from <Table>
where
day
between
<begindate>
and
<enddate>;
-- Regards M.Gresz :-)Received on Fri Oct 31 1997 - 00:00:00 CST
![]() |
![]() |