Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id C43369FB682 for ; Tue, 24 Apr 2007 13:41:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 05723-05 for ; Tue, 24 Apr 2007 13:41:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 02BA69FB6BA for ; Tue, 24 Apr 2007 13:41:27 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id E167C3552E; Tue, 24 Apr 2007 09:41:26 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DFC7B3552C; Tue, 24 Apr 2007 09:41:26 -0700 (PDT) Date: Tue, 24 Apr 2007 09:41:26 -0700 (PDT) From: Stephan Szabo To: "Penchalaiah P." Cc: pgsql-sql@postgresql.org Subject: Re: hi In-Reply-To: Message-ID: <20070424092234.V55902@megazone.bigpanda.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/234 X-Sequence-Number: 28234 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; or select t1.sno, t1.value, sum(t2.value) from temp as t1, temp as t2 where t1.ordering >= t2.ordering group by t1.ordering, t1.sno, t1.value order by t1.ordering;