Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Top 3 if each group
Message
 
 
À
14/10/2011 23:13:43
Hong Yew
People Quest
Malaisie
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01526519
Message ID:
01526559
Vues:
66
>Hi
>
>I have the following table
>
>Stud_ID Faculty Points
>----------- ---------- ---------
>001 ARTS 90
>002 ARTS 87
>003 ENG 87
>006 LAW 78
>
>I wish to extract the top 2 students of each faculty
>
>I would appreciate if you could help me with the SQL
>
>Thanks & Best Regards


This is very complex query in VFP, but Sergey has solved it before here Re: Select top 3 within a group Thread #1129690 Message #1129692

So, the query will be
SELECT * FROM csrFacilities mt1 ;
	WHERE NOT EXISTS (SELECT * FROM csrFacilities mt2 ;
				WHERE mt2.Faculty = mt1.Faculty ;
					AND mt2.Points > mt1.Points;
					HAVING COUNT(*) >= 2)
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform