Skip site navigation (1) Skip section navigation (2)

Re: Query performance

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Bill <bill(at)math(dot)uchicago(dot)edu>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query performance
Date: 2004-06-29 19:51:30
Message-ID: 20040629195130.GA1513@wolff.to (view raw or flat)
Thread:
Lists: pgsql-performance
On Tue, Jun 29, 2004 at 12:33:51 -0500,
  Bill <bill(at)math(dot)uchicago(dot)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.

In response to

Responses

pgsql-performance by date

Next:From: James AntillDate: 2004-06-29 21:56:36
Subject: Query gets slow when where clause increases
Previous:From: Richard HuxtonDate: 2004-06-29 19:03:25
Subject: Re: Query performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group