Re: Add calculated fields from one table to other table

Поиск
Список
Период
Сортировка
От roopa perumalraja
Тема Re: Add calculated fields from one table to other table
Дата
Msg-id 20061101064915.80874.qmail@web50812.mail.yahoo.com
обсуждение исходный текст
Ответ на Re: Add calculated fields from one table to other table  (Richard Broersma Jr <rabroersma@yahoo.com>)
Ответы Re: Add calculated fields from one table to other table
Список pgsql-sql
Hi Richard,
 
Thanks a lot.
 
I am sending you the create statement of tables & few insert statements as well. Hope this helps to solve the problem.
 
CREATE TABLE ticks
(
  tick_id int8 NOT NULL DEFAULT nextval(('ticks_s'::text)::regclass),
  ric varchar(30) NOT NULL,
  tick_date date NOT NULL,
  tick_time time NOT NULL,
  price float8,
  volume int4,
  CONSTRAINT ticks_pkey PRIMARY KEY (tick_id),
)
WITHOUT OIDS;
 
CREATE TABLE times
(
  times_time time NOT NULL,
  count int4,
  CONSTRAINT times_pkey PRIMARY KEY (times_time)
)
 
selct statement of ticks table
 ric | tick_date  |  tick_time   | price
-----+------------+--------------+-------
 A   | 2006-04-04 | 00:00:55.023 | 4.05  
 AA  | 2006-04-04 | 00:00:55.023 | 9.05
 A   | 2006-04-04 | 00:00:59.023 | 6.05   
 A   | 2006-04-04 | 00:01:00.023 | 5.05
 ABC | 2006-04-04 | 00:01:00.509 |12.00     
 ABI | 2006-04-04 | 00:01:03.511 |13.00     
 AA  | 2006-04-04 | 00:01:08.023 | 6.05     
 ABT | 2006-04-04 | 00:01:08.518 | 3.06
 ABT | 2006-04-04 | 00:01:09.518 | 7.06    
 
select statement of times table
times_time
-----------
 00:00:00       
 00:01:00       
 00:02:00       
       

I want the query result to look
ric | times_time | count | avg_price
----+------------+-------+-----------
 A  | 00:00:00   | 2  | 5.05
 AA | 00:00:00   | 1     | 9.05
ABC | 00:00:00   | 0     |
ABI | 00:00:00   | 0     |
ABT | 00:00:00   | 0     |
 A  | 00:01:00   | 1  | 5.05
 AA | 00:01:00   | 1     | 6.05
ABC | 00:01:00   | 1     |12.00
ABI | 00:01:00   | 1     |13.00
ABT | 00:01:00   | 2     | 5.06
 
I am really thankful to you.
 
Regards
Roopa


Richard Broersma Jr <rabroersma@yahoo.com> wrote:
> Hi Richard,
>
> Thanks a lot. I still am not able to get the result for all the rics in the ticks table but I
> am able to get the result for a particular ric.
>
> Can you help me with getting the result for all the rics in the ticks table
>
> Thanks
> Roopa

Could you send create table statements for the tables you are working on, and a few insert
statements for each table to have sample data. then show what you want the query results to look
like.

But from what you stated in your previous emails here is what I gather: maybe it might work?

select tk.ric as ric,
tm.times_time as minute, --timestamps by minutes
count(tk.*) as ,
...
from times tm
left join ticks tk
on (tm.times_time = date_trunc('minutes', tk.time))
group by ric, minute
order by minute;






We have the perfect Group for you. Check out the handy changes to Yahoo! Groups.

В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] Case Preservation disregarding case
Следующее
От: "Ezequias Rodrigues da Rocha"
Дата:
Сообщение: Re: Round Numeric Type