X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 181309DC833 for ; Sun, 12 Mar 2006 01:49:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32141-02 for ; Sun, 12 Mar 2006 01:49:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id E569D9DC83C for ; Sun, 12 Mar 2006 01:48:58 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k2C5msa5092780 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 11 Mar 2006 22:48:57 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k2C5msb0025601; Sat, 11 Mar 2006 22:48:54 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k2C5msPr025600; Sat, 11 Mar 2006 22:48:54 -0700 (MST) (envelope-from mfuhr) Date: Sat, 11 Mar 2006 22:48:54 -0700 From: Michael Fuhr To: Jeffrey Melloy Cc: Weimao Ke , pgsql-sql@postgresql.org Subject: Re: pgsql aggregate: conditional max Message-ID: <20060312054854.GA25553@winnie.fuhr.org> References: <4413AD1C.9050604@indiana.edu> <4413B301.7070207@visualdistortion.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4413B301.7070207@visualdistortion.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.121] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200603/171 X-Sequence-Number: 24517 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