Thread: query

query

From
Ankur Arora
Date:
hello there
i have a problem
i want to know the query for finding out aggregate

eg. i have a column named sum in table xyz

sum
----
2
4
7
5


i want a sql query that will give me another column alongwith this column as
aggregate

sum     aggregate
-----
2       2
4    6
7    13
5    18


if u could help me i will be obliged as i really need it on urgent basis

thanx
vibha


Re: query

From
Bruno Wolff III
Date:
On Sun, Jan 18, 2004 at 00:02:42 +1300,
  Ankur Arora <"Ankur Arora"@clear.net.nz> wrote:
> hello there
> i have a problem
> i want to know the query for finding out aggregate
>
> eg. i have a column named sum in table xyz
>
> sum
> ----
> 2
> 4
> 7
> 5
>
>
> i want a sql query that will give me another column alongwith this column as
> aggregate
>
> sum     aggregate
> -----
> 2       2
> 4    6
> 7    13
> 5    18
>
>
> if u could help me i will be obliged as i really need it on urgent basis

Its possible to do something like this with subqueries as long as there
is some way (e.g. additional columns) to order the table.

Then you could do something like:

select "sum", (select sum("sum") from xyz b where b.id <= a.id) from xyz a
  order by id;
This assumes there is a column named id which can be used to order the data.