Re: pgsql aggregate: conditional max

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
Cc: Weimao Ke <wke(at)indiana(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: pgsql aggregate: conditional max
Date: 2006-03-12 05:48:54
Message-ID: 20060312054854.GA25553@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Mar 12, 2006 at 12:34:57AM -0500, Jeffrey Melloy wrote:
> Should be able to do this with a standard max() aggregate.
>
> select aid, cat, max(weight)
> from table
> group by aid, cat;

That query returns the maximum weight for each (aid, cat) pair.
Against the example data it returns the entire table, not the
(aid, cat) pair with the max weight for a given aid.

--
Michael Fuhr

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel CAUNE 2006-03-12 14:05:37 Re: pgsql aggregate: conditional max
Previous Message Michael Fuhr 2006-03-12 05:42:12 Re: pgsql aggregate: conditional max