Re: running aggregates - Mailing list pgsql-sql

From Tomasz Myrta
Subject Re: running aggregates
Date
Msg-id 3F5798E8.3040004@klaster.net
Whole thread Raw
In response to running aggregates  (gdavy@tpg.com.au (Glenn))
List 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



pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: MINUS & ROWNUM in PostGres
Next
From: "Yaroslav Ulyanov"
Date:
Subject: Help me