pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: -anssi <anssiman@jippii.fi>
Cc: pgsql-sql@postgresql.org
Subject: Re: Useful SQL-statement?
Date: Wed, 24 Sep 2003 12:24:56 -0500
Message-ID: <20030924172456.GA11859@wolff.to> (raw)
In-Reply-To: <e88fd790.0309230134.14b56ec2@posting.google.com>
References: <e88fd790.0309230134.14b56ec2@posting.google.com>

On Tue, Sep 23, 2003 at 02:34:26 -0700,
  -anssi <anssiman@jippii.fi> 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.)



view thread (3+ messages)

Message-ID: <20030924172456.GA11859@wolff.to>
Permalink:  ../20030924172456.GA11859@wolff.to/
Also on:    postgresql.org/message-id/20030924172456.GA11859@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, anssiman@jippii.fi
  Subject: Re: Useful SQL-statement?
  In-Reply-To: <20030924172456.GA11859@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox