Re: Query performance - Mailing list pgsql-performance

From Bruno Wolff III
Subject Re: Query performance
Date
Msg-id 20040629195130.GA1513@wolff.to
Whole thread Raw
In response to Re: Query performance  ("Bill" <bill@math.uchicago.edu>)
Responses Re: Query performance
List pgsql-performance
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.

pgsql-performance by date:

Previous
From: "Mischa Sandberg"
Date:
Subject: Range query optimization
Next
From: "Scott Marlowe"
Date:
Subject: Re: High load average with PostgreSQL 7.4.2 on