Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select with Group by and Order by
Message
 
 
À
27/04/2010 21:01:21
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 6 SP5
Divers
Thread ID:
01462119
Message ID:
01462297
Vues:
38
>>
Select master_code, Count(*) As 'count' ;
>> FROM myTable ;
>> GROUP By master_code ;
>> INTO Cursor crsCounts
>>
>>Select t1.*, t2.Count ;
>> From myTable t1 ;
>> INNER Join crsCounts t2 ;
>> ON t1.master_code == t2.master_code ;
>> WHERE t1.master_ind = 'Y' Or t2.Count = 1
>>
>>PS: Having multiple SQL is both more manageable/readadble plus it is fast. Don't seek single SQL versions IMHO.
>>Cetin
>
>Yeah, I figured I could do it with multiple selects statements. I should have mentioned that the result set is going to be an updateable view that drives a form. Thanks for taking the time.
>
>Tim

In VFP9 you can combine two of them into one using derived tables.

In VFP6:
select max(Master_ind) as Master_Ind, Master_Code, count(*) as RecCount from myTable T1
where Master_Ind = 'Y' or not exists(select 1 from myTable T where T.Master_Code  = T1.Master_Code and Master_Ind = 'Y')
group by Master_Code
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