pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: roopa perumalraja <roopabenzer@yahoo.com>
To: pgsql-sql@postgresql.org, Richard Broersma Jr <rabroersma@yahoo.com>
Subject: Re: Add calculated fields from one table to other table
Date: Tue, 31 Oct 2006 22:49:15 -0800 (PST)
Message-ID: <20061101064915.80874.qmail@web50812.mail.yahoo.com> (raw)
In-Reply-To: <50323.50500.qm@web31808.mail.mud.yahoo.com>

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.

view thread (18+ messages)  latest in thread

Message-ID: <20061101064915.80874.qmail@web50812.mail.yahoo.com>
Permalink:  ../20061101064915.80874.qmail@web50812.mail.yahoo.com/
Also on:    postgresql.org/message-id/20061101064915.80874.qmail@web50812.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: roopabenzer@yahoo.com, rabroersma@yahoo.com
  Subject: Re: Add calculated fields from one table to other table
  In-Reply-To: <20061101064915.80874.qmail@web50812.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox