Re: Query performance

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: Query performance
Дата
Msg-id 20040629195130.GA1513@wolff.to
обсуждение исходный текст
Ответ на Re: Query performance  ("Bill" <bill@math.uchicago.edu>)
Ответы Re: Query performance  ("Bill" <bill@math.uchicago.edu>)
Список 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 по дате отправления:

Предыдущее
От: "Mischa Sandberg"
Дата:
Сообщение: Range query optimization
Следующее
От: "Scott Marlowe"
Дата:
Сообщение: Re: High load average with PostgreSQL 7.4.2 on