Re: hi - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: hi
Date
Msg-id 20070424092234.V55902@megazone.bigpanda.com
Whole thread Raw
In response to hi  ("Penchalaiah P." <penchalaiahp@infics.com>)
List pgsql-sql
On Tue, 24 Apr 2007, Penchalaiah P. wrote:

> Hi
>
> I have the data like this in temp table
>
> SQL> Select sno, value from temp;
>
> SNO                           Value
>
> 1                     650.00
>
> 2                     850.00
>
> 3                     640.00
>
> 3                     985.00
>
> 5                     987.00
>
> 9                     9864.00
>
> 7                     875.00

Tables are not ordered.  You'll need something like an ordering column
that represents the ordering and is unique.

Then you can probably do something like (untested):select sno, value, (select sum(value) as sum from temp t where
t.ordering<=temp.ordering) from temp order by ordering;
 
orselect t1.sno, t1.value, sum(t2.value) from temp as t1, temp as t2 wheret1.ordering >= t2.ordering group by
t1.ordering,t1.sno, t1.value orderby t1.ordering;
 


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Function to return a multiple colmn table or view
Next
From: Richard Albright
Date:
Subject: plpgsql array looping