Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select top 3 within a group
Message
 
 
À
16/06/2006 20:07:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01129690
Message ID:
01368740
Vues:
23
Please see this thread http://forums.asp.net/t/1362385.aspx with very interesting solution.
select [id],[name]
from test as A1
where (select count(*) from test as A2 where A2.[id]=A1.[id] and A2.name<=A1.name )<=2
order by [id]
>Hi all,
>
>I have a mytable with 2 fields:
>
>team score
>AAAA 10
>AAAA 12
>AAAA 14
>AAAA 16
>AAAA 18
>AAAA 20
>AAAA 22
>
>BBBB 11
>BBBB 22
>BBBB 33
>BBBB 44
>BBBB 55
>BBBB 66
>
>CCCC 22
>CCCC 77
>CCCC 88
>CCCC 99
>
>DDDD 10
>DDDD 12
>
>to have in mynewtable AT LEAST the top 3 in each team if that team has more
>than 3 records.
>
>team score
>AAAA 22
>AAAA 20
>AAAA 18
>
>
>BBBB 66
>BBBB 55
>BBBB 44
>
>CCCC 99
>CCCC 88
>CCCC 77
>
>DDDD 12
>DDDD 10
>
>I try this SQL statement but not work.
>
>
>
>SELECT TOP 3 TEAM,SCORE FROM MYTABLE WHERE TEAM IN ( SELECT TEAM,SCORE FROM MYTABLE ORDER BY TEAM, SCORE DESC;
>
>
>
>Please assist to correct my sql.
>
>TIA
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform