pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUseful SQL-statement?
3+ messages / 3 participants
[nested] [flat]
* Useful SQL-statement?
@ 2003-09-23 09:34 -anssi <anssiman@jippii.fi>
0 siblings, 2 replies; 3+ messages in thread
From: anssiman@jippii.fi @ 2003-09-23 09:34 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Useful SQL-statement?
@ 2003-09-24 17:23 Tomasz Myrta <jasiek@klaster.net>
parent: -anssi <anssiman@jippii.fi>
1 sibling, 0 replies; 3+ messages in thread
From: Tomasz Myrta @ 2003-09-24 17:23 UTC (permalink / raw)
To: -anssi <anssiman@jippii.fi>; +Cc: pgsql-sql
> 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
Sure:
select distinct on (team) player,team,points
from resultset
order by team asc, points desc
Regards,
Tomasz Myrta
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Useful SQL-statement?
@ 2003-09-24 17:24 Bruno Wolff III <bruno@wolff.to>
parent: -anssi <anssiman@jippii.fi>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2003-09-24 17:24 UTC (permalink / raw)
To: -anssi <anssiman@jippii.fi>; +Cc: pgsql-sql
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.)
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-09-24 17:24 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-23 09:34 Useful SQL-statement? -anssi <anssiman@jippii.fi>
2003-09-24 17:23 ` Tomasz Myrta <jasiek@klaster.net>
2003-09-24 17:24 ` Bruno Wolff III <bruno@wolff.to>
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