Re: query - Mailing list pgsql-novice

From Bruno Wolff III
Subject Re: query
Date
Msg-id 20040119052013.GA19053@wolff.to
Whole thread Raw
In response to query  (Ankur Arora <"Ankur Arora"@clear.net.nz>)
List pgsql-novice
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.

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: installing postgre
Next
From: Tom Lane
Date:
Subject: Re: Discarding UNIQUE temporarily?