Re: Non-aggregate values attached to aggregates? - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Non-aggregate values attached to aggregates?
Date
Msg-id 20041216220932.GA8143@winnie.fuhr.org
Whole thread Raw
In response to Non-aggregate values attached to aggregates?  (Benjamin Smith <lists@benjamindsmith.com>)
Responses Re: Non-aggregate values attached to aggregates?
List pgsql-general
On Thu, Dec 16, 2004 at 01:38:19PM -0800, Benjamin Smith wrote:

> I have a list of students, and a list of enrollment records, and I'm trying to
> get a list of students and their most recent enrollment/disenrollment dates.

If you don't mind using a non-standard construct, see the documentation
for SELECT DISTINCT ON.

http://www.postgresql.org/docs/7.4/static/queries-select-lists.html#QUERIES-DISTINCT
http://www.postgresql.org/docs/7.4/static/sql-select.html#SQL-DISTINCT

> Dates are kept as ]YYYYMMDD', eg 2004114 for Nov 14, 2004.

Why not use a DATE type?  You can reformat it with to_char() if
need be.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Non-aggregate values attached to aggregates?
Next
From: "Net Virtual Mailing Lists"
Date:
Subject: tsearch2 avoiding firing of triggers.....