X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 64188D1B1B4 for ; Tue, 29 Jun 2004 14:33:54 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09655-04 for ; Tue, 29 Jun 2004 17:33:48 +0000 (GMT) Received: from math.uchicago.edu (math.uchicago.edu [128.135.72.38]) by svr1.postgresql.org (Postfix) with ESMTP id 33A6DD1B1AA for ; Tue, 29 Jun 2004 14:33:46 -0300 (ADT) Received: from billnotebook (wireless-197-223.uchicago.edu [128.135.197.223]) by math.uchicago.edu (8.12.10/8.12.10) with ESMTP id i5THXkfL031311 for ; Tue, 29 Jun 2004 12:33:46 -0500 Message-Id: <200406291733.i5THXkfL031311@math.uchicago.edu> From: "Bill" To: Subject: Re: Query performance Date: Tue, 29 Jun 2004 12:33:51 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 In-Reply-To: <40E12A5D.70007@archonet.com> Thread-Index: AcRdtTtifCTAR38tQAerxJIonFzvKQASJpwg X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/311 X-Sequence-Number: 7369 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? Here is an example if needed. Say we have a stock by the name of YYY I know, due to query 1 that stock YYY has a abs(close-open)/open price ratio of for example, 1.3 on Dec 1 and (for simplicity let's say we only have two dates) and Dec 2 the ratio for YYY is 1.5. So the query averages and gets 1.4. Now it needs to do this for all of the stocks in the table and sort by increasing ratio. Thanks. -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Richard Huxton Sent: Tuesday, June 29, 2004 3:38 AM To: Bill Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] Query performance Bill wrote: > Ok....so here lies the output of oclh (i.e "\d oclh") > > Table "public.oclh" > Column | Type | Modifiers > --------+-----------------------+------------------------------- > symbol | character varying(10) | not null default '' > date | date | not null default '0001-01-01' > open | numeric(12,2) | not null default '0.00' > close | numeric(12,2) | not null default '0.00' > low | numeric(12,2) | not null default '0.00' > high | numeric(12,2) | not null default '0.00' > Indexes: symbol_2_oclh_index btree (symbol, date), > symbol_oclh_index btree (symbol, date) Well, I'm not sure why the two indexes on the same columns, and I'm not sure it makes sense to have defaults for _any_ of the columns there. So - you want: 1. ratio = abs(closing-opening)/opening 2. average = all the ratios of each day of each stock 3. Highest average Well, I don't know what you mean by #2, but #1 is just: SELECT symbol, "date", abs(close - open)/open AS ratio FROM oclh GROUP BY symbol, date; I'd probably fill in a summary table with this and use that as the basis for your further queries. Presumably from "yesterday" back, the ratios/averages won't change. -- Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org