Обсуждение: Useful SQL-statement?

Поиск
Список
Период
Сортировка

Useful SQL-statement?

От
anssiman@jippii.fi (-anssi)
Дата:
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


Re: Useful SQL-statement?

От
Bruno Wolff III
Дата:
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.bestand 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.)


Re: Useful SQL-statement?

От
Tomasz Myrta
Дата:
> 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