pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Help with sub query
2+ messages / 2 participants
[nested] [flat]

* Help with sub query
@ 2007-03-19 02:56  roopa perumalraja <roopabenzer@yahoo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: roopa perumalraja @ 2007-03-19 02:56 UTC (permalink / raw)
  To: pgsql-sql

Hi all,
   
  I want the last value from the group of rows. The table 'index_prices' is
   
  index_code price_time price
   
  XYZ            09:45:00   7.5
  XYZ            09:46:00   7.4
  XYZ            09:59:00   7.2
  XYZ            10:00:00   7.3
  XYZ            10:01:00   7.6
  XYZ            10:02:00   7.3
  .
  .
  .
   
  The other table 'times' is for time interval
   
  snapshot_time
   
  10:00:00
  10:30:00
  11:00:00
   
  I want the last value of the price between the interval of time. So I do 
   
  select tm.index_code, tm.price_date, t.snapshot_time, last(tm.price)
from index_prices_200703 tm, times t where tm.index_code = 'XYZ' and tm.price_time >= (t.snapshot_time - '30 minute' :: interval)::time and tm.price_time < t.snapshot_time  
group by t.snapshot_time, tm.price_date, tm.index_code order by tm.index_code, tm.price_date, t.snapshot_time; 
   
  The last() doesn't work. Can this be done using sub query?
   
  Thanks in advance

 
---------------------------------
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Help with sub query
@ 2007-03-19 04:03  Phillip Smith <phillip.smith@weatherbeeta.com.au>
  parent: roopa perumalraja <roopabenzer@yahoo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Phillip Smith @ 2007-03-19 04:03 UTC (permalink / raw)
  To: 'roopa perumalraja' <roopabenzer@yahoo.com>; pgsql-sql

Add something like this to your query:

 

ORDER BY price_time LIMIT 1

 

Cheers,

~p

 

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of roopa perumalraja
Sent: Monday, 19 March 2007 13:56
To: pgsql-sql@postgresql.org
Subject: [SQL] Help with sub query

 

Hi all,

 

I want the last value from the group of rows. The table 'index_prices' is

 

index_code price_time price

 

XYZ            09:45:00   7.5

XYZ            09:46:00   7.4

XYZ            09:59:00   7.2

XYZ            10:00:00   7.3

XYZ            10:01:00   7.6

XYZ            10:02:00   7.3

.

.

.

 

The other table 'times' is for time interval

 

snapshot_time

 

10:00:00

10:30:00

11:00:00

 

I want the last value of the price between the interval of time. So I do 

 

select tm.index_code, tm.price_date, t.snapshot_time, last(tm.price)
from index_prices_200703 tm, times t where tm.index_code = 'XYZ' and
tm.price_time >= (t.snapshot_time - '30 minute' :: interval)::time and
tm.price_time < t.snapshot_time  
group by t.snapshot_time, tm.price_date, tm.index_code order by
tm.index_code, tm.price_date, t.snapshot_time; 

 

The last() doesn't work. Can this be done using sub query?

 

Thanks in advance

  

  _____  

Food
<http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOAR
fcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&sid=39654
5367>  fight? Enjoy some healthy debate
in the Yahoo!
<http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOAR
fcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&sid=39654
5367>  Answers Food & Drink Q&A.



*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-03-19 04:03 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 02:56 Help with sub query roopa perumalraja <roopabenzer@yahoo.com>
2007-03-19 04:03 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>

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