Received: from mail.rdc2.bc.home.com (ha1.rdc2.bc.wave.home.com [24.2.10.68]) by hub.org (8.10.1/8.10.1) with ESMTP id e7I6DWm51040; Fri, 18 Aug 2000 02:13:33 -0400 (EDT) Received: from home.com ([24.112.123.252]) by mail.rdc2.bc.home.com (InterMail vM.4.01.03.00 201-229-121) with ESMTP id <20000818061332.UYQB3271.mail.rdc2.bc.home.com@home.com>; Thu, 17 Aug 2000 23:13:32 -0700 Message-ID: <399CD3DC.F028B264@home.com> Date: Thu, 17 Aug 2000 23:12:44 -0700 From: Craig Johannsen X-Mailer: Mozilla 4.74 [en] (X11; U; Linux 2.2.15-4mdk i686) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: ian.schumacher@telus.net, Francisco Hernandez , pgsql-general@postgresql.org Subject: Re: Re: [SQL] variables in SQL?? References: <000f01c0074f$4dcd87e0$700c2304@francisco> <399A7D6C.20593252@dohle.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200008/401 You can create a running total provided that you have a unique sequentially increasing (or decreasing) ID for each row. See the following example: create table tran(id int primary key, price dec(8,2)); insert into tran values(1,5.00); insert into tran values(2,4.00); insert into tran values(3,10.00); insert into tran values(4,2.00); insert into tran values(5,7.00); select price, (select sum(price) from tran as d1 where d1.id <= d2.id) as "sum" from tran as d2; price | sum -------+------- 5.00 | 5.00 4.00 | 9.00 10.00 | 19.00 2.00 | 21.00 7.00 | 28.00 (5 rows) Francisco wrote: > > what im trying to do is have a Sum of a colum.. as it goes forwards with the > > cursor.. > > like so: > > > > Price|Sum > > 5|5 > > 4|9 > > 10|19 > > 2|21 > > 7|28 > ==================================== Craig Johannsen Critical Path Consulting, Inc. 604-762-1514 http://members.home.net/cjohan/cpath ====================================