Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SELECTing MAX()
Message
De
12/12/2000 23:53:17
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
 
À
12/12/2000 21:18:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00452686
Message ID:
00452745
Vues:
21
>What would be the best way to do this in a SELECT statment?
>I have a table with scores. Each person may have more than one score but I need to select only the highest for EACH person.
>
>I am not sure how to do it in a subquery. I tried something like this but of course is not good:
>SELECT * FROM myCur WHERE id = id;
>AND score IN ;
> (SELECT MAX(score) FROM myCur)
>
>thanks in advance

If I understood you well, you want to select the records which hold each persons highest scores (i.e. not just any record with the max of the score). I figure it would go like this

select id, max(score) as maxsc from mycur into curs maxcur
SELECT myCur.* FROM myCur, maxsc WHERE ;
mycur.id=maxsc.id and mycur.score=maxsc.score

If someone would have two records with the result equal to their max, you'll get them both, unless we include GROUP BY mycur.ID in the second select.

There'd probably be someone who can do this in an one-liner, but I'm just too tired at this moment :)

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform