X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 561C7D1BADA for ; Thu, 4 Sep 2003 19:56:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 78567-03 for ; Thu, 4 Sep 2003 16:56:08 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id CE160D1BAB6 for ; Thu, 4 Sep 2003 16:56:04 -0300 (ADT) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 9C8A52B3A4; Thu, 4 Sep 2003 21:55:57 +0200 (CEST) Message-ID: <3F5798E8.3040004@klaster.net> Date: Thu, 04 Sep 2003 21:56:24 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5a) Gecko/20030718 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Glenn Cc: pgsql-sql@postgresql.org Subject: Re: running aggregates References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/21 X-Sequence-Number: 14999 > f1 sum_f1 avg_f1 pseudo_recno > 10 10 10 1 > 20 30 15 2 > 30 60 20 3 > 40 100 25 4 > 50 150 30 5 > 60 210 35 6 > > I know I can do this by iterating with a plpgsql routine, but there must > be a means simply using SQL select f1 t1.f1, sum(t2.f1) as sum_f1, avg(t2.f1) as avg_f1, count(*) as pseudo_recno from ttt t1 join ttt t2 on (t2.f1<=t1.t1) group by t1.f1 order by t1.f1; Regards, Tomasz Myrta