Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The max value of a given group
Message
De
17/03/2004 11:39:14
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00887108
Message ID:
00887113
Vues:
14
This message has been marked as the solution to the initial question of the thread.
Hi Enmanuel,

Try
* Get key fields for oldest members 
SELECT Family, Level, MAX(Age) AS Age ;
	FROM mytable ;
	GROUP BY 1,2 ;
	INTO CURSOR crsOldestKey NOFILTER

* Get all fields	
SELECT mt.Family, mt.Name, mt.Level, mt.Age ;	
	FROM mytable mt ;
		JOIN  crsOldestKey cok ON cok.Family = mt.Family ;
			AND cok.Level = mt.Level ;
			AND cok.Age = mt.Age
>Hi all, I have a table with the following fields: Family, name, age and level. In this table a family can have several members and I need a SQL statement that gets me the older member of each family order by level. For example:
>
>
>Family  Name      Age    Level
>--------------------------------
>01      xxxxxxxx   15      1
>01      xxxxxxxx   13      1
>01      xxxxxxxx   17      2
>02      xxxxxxxx   12      1
>02      xxxxxxxx   15      1
>02      xxxxxxxx   13      1
>03      xxxxxxxx   13      1
>03      xxxxxxxx   18      2
>03      xxxxxxxx   12      1
>
>
>
>The result should be:
>
>
>Family  Name      Age    Level
>--------------------------------
>01      xxxxxxxx   15      1
>02      xxxxxxxx   15      1
>03      xxxxxxxx   13      1
>01      xxxxxxxx   17      2
>03      xxxxxxxx   18      2
>
>
>
>Any help is greatly appreciated!
>
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform