Aggregate functions

From: "John Duffy" <jbduffy(at)cwcom(dot)net>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Aggregate functions
Date: 2001-02-04 19:28:04
Message-ID: 002801c08ee0$aab41140$75cc2cc3@desktop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi.

I have a simple table in which I store equity prices:

table prices (
equity_id integer,
date date,
price money);

I am happy with the following select statement:

SELECT equity_id, min(price), max(price)
FROM prices
WHERE date >= start_date AND date <= end_date
GROUP BY equity_id;

which produces a nice table of min and max prices for each equity between
two dates.

What I would like to be able to do is a select like this:

SELECT equity_id, start_date(price), end_date(price), min(price),
max(price)
...

Are there aggregate function, such as 'first' and 'last', that will store
the first and last row value of a series of rows ?

I have read the Extending Aggregates section of the Programmers Guide but it
is a bit beyond me. Any assistance in writing functions to do the above
would be appreciated.

Regards
John Duffy
jbduffy(at)cwcom(dot)net

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-02-04 19:50:24 Re: Aggregate functions
Previous Message Tom Lane 2001-02-04 18:47:36 Re: DEBUG strings