From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
---|---|
To: | roopa perumalraja <roopabenzer(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Add calculated fields from one table to other table |
Date: | 2006-10-26 17:59:34 |
Message-ID: | 20061026175934.78136.qmail@web31806.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> I have two tables. Tick table has fields like ticker, time, price & volume and Timeseries
> table has fields like ticker, time, avg_price, avg_volume.
>
> The time field in Timeseries table is different from time in tick table, its the timeseries
> for every minute. Now I want to calculate the average price & volume from tick table for each
> ticker and for every minute and add those fields to timeseries table. Can anyone please help me
> out with the sql query.
>
> Note: The ticker in the tick table also has duplicate values, so i am not able to create
> relation between two tables.
Here is my guess how it can be done:
insert into Timeseries ( tiker, time, avg_price, avg_volume ) select ...
where select .... would be
select tick,
date_trunc('minute', time) as minute,
avg(price) as avg_price,
avg(volume) as avg_volume
from ticker
where time between 'yourstartdate' and 'yourenddate'
group by tick, minute;
Regards,
Richard Broersma Jr.
From | Date | Subject | |
---|---|---|---|
Next Message | Aaron Bono | 2006-10-26 22:57:40 | Re: plpgsql record as parameter ??? |
Previous Message | chester c young | 2006-10-26 15:29:00 | Re: Add calculated fields from one table to other table |