From: roopa perumalraja <roopabenzer@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Help with sub query
Date: Sun, 18 Mar 2007 19:56:01 -0700 (PDT)
Message-ID: <621391.5824.qm@web50808.mail.re2.yahoo.com> (raw)
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.
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
Subject: Re: Help with sub query
In-Reply-To: <621391.5824.qm@web50808.mail.re2.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