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
I want the last value from the group of rows. The table 'index_prices' is
index_code price_time price
The other table 'times' is for time interval
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?
Food fight? Enjoy some healthy debate
in the Yahoo! 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