pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Kindler <christian.kindler@gmx.net>
To: roopa perumalraja <roopabenzer@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Solution to retrieve first and last row for each minute
Date: Wed, 22 Aug 2007 10:49:49 +0200
Message-ID: <20070822084949.158210@gmx.net> (raw)

Hi!

Do something like this

http://fimi.cvs.sourceforge.net/fimi/database/defaults/indicators/myinttick2bar.sql?revision=1.3&...

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



view thread (4+ messages)  latest in thread

Message-ID: <20070822084949.158210@gmx.net>
Permalink:  ../20070822084949.158210@gmx.net/
Also on:    postgresql.org/message-id/20070822084949.158210@gmx.net

 · 

reply

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: christian.kindler@gmx.net, roopabenzer@yahoo.com
  Subject: Re: Solution to retrieve first and last row for each minute
  In-Reply-To: <20070822084949.158210@gmx.net>

* 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