Re: Non-aggregate values attached to aggregates?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: lists(at)benjamindsmith(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Non-aggregate values attached to aggregates?
Date: 2004-12-16 21:57:56
Message-ID: 1690.1103234276@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Benjamin Smith <lists(at)benjamindsmith(dot)com> writes:
> 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.

I don't know any nice way to solve this type of problem in bog-standard SQL.
But it's pretty easy to solve using Postgres' DISTINCT ON extension.
Look at the "weather reports" example in the SELECT reference page
for inspiration.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2004-12-16 22:09:32 Re: Non-aggregate values attached to aggregates?
Previous Message Benjamin Smith 2004-12-16 21:38:19 Non-aggregate values attached to aggregates?