Re: SQL Agreate Functions

From: Richard Huxton <dev(at)archonet(dot)com>
To: Alex P <alex(at)meerkatsoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Agreate Functions
Date: 2004-11-02 09:32:17
Message-ID: 41875421.8090804@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alex P wrote:
> Hi,
>
> I have a problem I dont really know how to solve except for writing a
> function.
[snip]
> What I would like to calculate is:
>
> a) the difference of the past 2 days for every security of
> available prices

Find the maximum date for a give SecCode (simple enough) and then the
maximum date that is smaller than the one you just found (assuming no
repetition of dates for a given SecCode).

> b) a flag indicating, that the price of today-1 is yesterday's
> price (true in case A0001, false for A0002)

SELECT ... (PriceDate = (CURRENT_DATE - 1)) AS is_yesterday, ...

> c) the variance of the past 30 days

Variance aggregate function

> Is it possible to do that within one query?

Three sub-queries and some joining, certainly. It'll be a big query
mind, perhaps worth wrapping in a function.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2004-11-02 09:35:30 Re: Postgres Versions / Releases
Previous Message Richard Huxton 2004-11-02 09:27:09 Re: Subselect Question