Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 220299F97F3 for ; Wed, 22 Aug 2007 05:49:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 69374-01 for ; Wed, 22 Aug 2007 05:49:49 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id ABCCA9F97EE for ; Wed, 22 Aug 2007 05:49:51 -0300 (ADT) Received: (qmail 24767 invoked by uid 0); 22 Aug 2007 08:49:50 -0000 Received: from 195.141.84.215 by www160.gmx.net with HTTP; Wed, 22 Aug 2007 10:49:49 +0200 (CEST) Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset="us-ascii" Date: Wed, 22 Aug 2007 10:49:49 +0200 From: "Christian Kindler" Message-ID: <20070822084949.158210@gmx.net> MIME-Version: 1.0 Subject: Re: Solution to retrieve first and last row for each minute To: "roopa perumalraja" X-Authenticated: #27759442 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX19TXLJWMAZTbAhGrmEFiqKgQF0V8e82pFpvOLkrAG SHKlXtNBHo17F3DRNsmWkV+zoPbJrqNnH5lw== Content-Transfer-Encoding: 7bit X-GMX-UID: y5yjC/ZcbHIhUCCrnjU0DyIiJihyalBB X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.013 tagged_above=0 required=5 tests=BAYES_50=0.001, FAKE_REPLY_C=2.012 X-Spam-Level: ** X-Archive-Number: 200708/190 X-Sequence-Number: 29128 Hi! Do something like this http://fimi.cvs.sourceforge.net/fimi/database/defaults/indicators/myinttick2bar.sql?revision=1.3&view=markup and replace the max / min calculation with a count calculation. Cheers Chris On Wed, August 22, 2007 9:25 am, roopa perumalraja wrote: > Hi all, > > I have a table trans with the data > > price | volume | date | time > : > : > > I need to get the first and last price per every minute along with > count, average, maximum, minumum of the price and sum of the volume . > Right now I have my query which calculates count, maximum, minimum and > average. > > select trnew.date, trnew.trunc_time, count(*) as count, > avg(trnew.price) as avg_price, > sum(trnew.price*trnew.volume)/sum(trnew.volume) as vwap, > max(trnew.price) as high_price, min(trnew.price) as low_price, > sum(trnew.volume) as sum_volume from (select tr.date, > date_trunc('minute', tr.time) - interval '4 hour' as trunc_time, > tr.price, tr.volume from trans tr > where tr.time between '13:30:00.00' and '20:00:0.00' ) as trnew > group by trnew.date, trnew.trunc_time order by trnew.date, > trnew.trunc_time; > > How do I add first and last price for each minute to this query? > > Thanks a lot in advance. > > Cheers. > > > --------------------------------- > Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user > panel and lay it on us. -- cu Chris Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten Browser-Versionen downloaden: http://www.gmx.net/de/go/browser