Re: running aggregates

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Glenn <gdavy(at)tpg(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: running aggregates
Date: 2003-09-04 19:56:24
Message-ID: 3F5798E8.3040004@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message George Weaver 2003-09-04 20:48:00 Re: Help me
Previous Message Rod Taylor 2003-09-04 19:50:28 Re: MINUS & ROWNUM in PostGres