Re: Non-aggregate values attached to aggregates?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Benjamin Smith <lists(at)benjamindsmith(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Non-aggregate values attached to aggregates?
Date: 2004-12-16 22:09:32
Message-ID: 20041216220932.GA8143@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Net Virtual Mailing Lists 2004-12-16 22:21:22 tsearch2 avoiding firing of triggers.....
Previous Message Tom Lane 2004-12-16 21:57:56 Re: Non-aggregate values attached to aggregates?