running aggregates

Поиск
Список
Период
Сортировка
Искать

running aggregates

От:
gdavy@tpg.com.au (Glenn)
Дата:
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

Thanks in advance
Glenn
ps sorry if this isn't the appropriate use for this forum

Re: running aggregates

От:
Tomasz Myrta <jasiek@klaster.net>
Дата:
> 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


FAQ