Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id ADA3C9FB33D for ; Sun, 18 Mar 2007 23:56:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 34259-04 for ; Sun, 18 Mar 2007 23:56:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from web50808.mail.re2.yahoo.com (web50808.mail.re2.yahoo.com [206.190.38.117]) by postgresql.org (Postfix) with SMTP id 15A009FB33C for ; Sun, 18 Mar 2007 23:56:02 -0300 (ADT) Received: (qmail 8976 invoked by uid 60001); 19 Mar 2007 02:56:01 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=mdUbrz63vjAk2CGVCOL3/oIBfeTFbKCjbRdI92UIWXtF7mPVssIjmK6lnYgOzEhDN9I0FnN2b2XW1KxA9+C3mQjXJUO2+L9A303iw77nJl1RaDLdEpKG/2fygfVBlyNGo0JJIup6EzdMCuiGG+H+GK4EGSOB/cSUAqLaVbvw6rE=; X-YMail-OSG: Xc0na5MVM1nrv.HgV8FuarLTMek_Ezu0y9rkX29WEWu6uz5F9zWbCuWg55VxVF9dffHROUnVwLd1C3RSavp.jz4ecbNrrvCs0RuM6K_nQWMGvIEMXvfEEfG8M9IOrUlEn6e8EzzlelsIJ78gm1JLpUoH Received: from [203.134.174.70] by web50808.mail.re2.yahoo.com via HTTP; Sun, 18 Mar 2007 19:56:01 PDT Date: Sun, 18 Mar 2007 19:56:01 -0700 (PDT) From: roopa perumalraja Subject: Help with sub query To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1184913863-1174272961=:5824" Content-Transfer-Encoding: 8bit Message-ID: <621391.5824.qm@web50808.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.75 tagged_above=0 required=5 tests=BAYES_20, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, HTML_50_60, HTML_MESSAGE X-Spam-Level: ** X-Archive-Number: 200703/241 X-Sequence-Number: 27879 --0-1184913863-1174272961=:5824 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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. --0-1184913863-1174272961=:5824 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
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. --0-1184913863-1174272961=:5824--