X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 68EF2D1B52C for ; Wed, 24 Sep 2003 17:18:36 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 78270-04 for ; Wed, 24 Sep 2003 14:18:06 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id E765CD1B511 for ; Wed, 24 Sep 2003 14:18:04 -0300 (ADT) Received: (qmail 11929 invoked by uid 500); 24 Sep 2003 17:24:56 -0000 Date: Wed, 24 Sep 2003 12:24:56 -0500 From: Bruno Wolff III To: -anssi Cc: pgsql-sql@postgresql.org Subject: Re: Useful SQL-statement? Message-ID: <20030924172456.GA11859@wolff.to> Mail-Followup-To: -anssi , pgsql-sql@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/286 X-Sequence-Number: 15264 On Tue, Sep 23, 2003 at 02:34:26 -0700, -anssi wrote: > Hello! > > Is there any standard SQL-statement, which produce > resultset containing best plyers of the each team? > > player |team|points > ------------------- > paul col 10 > peter col 12 > steve det 12 > sergei det 8 > jere dal 4 > > Resultset: > > peter > steve > jere select player from tablename a, (select team, max(points) as best from tablename group by team) b where a.points = b.best and a.team = b.team; This will list all of the players who have scored the maximum number of points for a team. (Note I didn't actually test this, so there may be minor errors in the example.)