agora inbox for pgsql-performance@postgresql.org  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Bill <bill@math.uchicago.edu>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query performance
Date: Tue, 29 Jun 2004 14:51:30 -0500
Message-ID: <20040629195130.GA1513@wolff.to> (raw)
In-Reply-To: <200406291733.i5THXkfL031311@math.uchicago.edu>
References: <40E12A5D.70007@archonet.com>
	<200406291733.i5THXkfL031311@math.uchicago.edu>

On Tue, Jun 29, 2004 at 12:33:51 -0500,
  Bill <bill@math.uchicago.edu> wrote:
> Ok, thanks.  So let me explain the query number 2 as this is the more
> difficult to write.  So I have a list of stocks, this table contains the
> price of all of the stocks at the open and close date.  Ok, now we have a
> ratio from query (1) that returns at least a very rough index of the daily
> performance of a given stock, with each ratio representing the stock's
> performance in one day.  Now we need to average this with the same stock's
> ratio every day, to get a total average for each stock contained in the
> database.  Now I would simply like to find a ratio like this that represents
> the average of every stock in the table and simply find the greatest ratio.
> Sorry about the lousy explanation before, is this a bit better?

You can do something like:

SELECT symbol, avg((open-close)/open) GROUP BY symbol
  ORDER BY avg((open-close)/open) DESC LIMIT 1;

If you aren't interested in the variance of the daily change, it seems like
you would be best off using the opening price for the first day you have
recorded for the stock and the closing price on the last day and looking
at the relative change.



view thread (48+ messages)  latest in thread

Message-ID: <20040629195130.GA1513@wolff.to>
Permalink:  ../20040629195130.GA1513@wolff.to/
Also on:    postgresql.org/message-id/20040629195130.GA1513@wolff.to

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-performance@postgresql.org
  Cc: bruno@wolff.to, bill@math.uchicago.edu
  Subject: Re: Query performance
  In-Reply-To: <20040629195130.GA1513@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox