Re: SELECT Question

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Alex <alex(at)meerkatsoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT Question
Date: 2006-03-03 17:15:01
Message-ID: 20060303171501.GA15289@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Mar 04, 2006 at 03:35:02 +1100,
Alex <alex(at)meerkatsoft(dot)com> wrote:
> Hi,
> i want to calculate the price difference, change% of 2 price records. Is
> there an easy way to do that within one query, rather than writing a
> function?

You can use a self join to do this. It won't be spectaculatly fast though.
The idea is too join each record to the record with the largest date less
than the date of the current record. Note that on record won't have a match.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2006-03-03 17:28:23 Re: Problem with function that returns a cursor
Previous Message Scott Marlowe 2006-03-03 17:10:04 Re: ERROR: column "datpath" does not exist