pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Myrta <jasiek@klaster.net>
To: Glenn <gdavy@tpg.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: running aggregates
Date: Thu, 04 Sep 2003 21:56:24 +0200
Message-ID: <3F5798E8.3040004@klaster.net> (raw)
In-Reply-To: <c865c69d.0309011246.5ef4cfb2@posting.google.com>
References: <c865c69d.0309011246.5ef4cfb2@posting.google.com>

> 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




view thread (2+ messages)

Message-ID: <3F5798E8.3040004@klaster.net>
Permalink:  ../3F5798E8.3040004@klaster.net/
Also on:    postgresql.org/message-id/3F5798E8.3040004@klaster.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jasiek@klaster.net, gdavy@tpg.com.au
  Subject: Re: running aggregates
  In-Reply-To: <3F5798E8.3040004@klaster.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox