Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with MAX() in SELECT
Message
 
 
À
23/01/2002 09:51:00
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrats & ententes
Divers
Thread ID:
00608962
Message ID:
00609503
Vues:
19
Hi Agnes,

VFP returns values for the fields not included in the GROUP BY clause from the last physical record in the group not from the record with MAX()/MIN() value. You can get desired result with two selects
SELECT;
 Work_Table.Code, MAX(Ref_Table.Code) as max_code;
 FROM Work_Table ;
 INNER JOIN Ref_Table ;
 ON Work_Table.Code = STRTRAN(Ref_Table.Code, " ", "") ;
 GROUP BY 1 ;
 INTO CURSOR temp1

SELECT;
 temp1.Code, ref_Table.Key, temp1.max_Code ;
 FROM temp1 ;
 JOIN Ref_Table ;
	 ON temp1.max_Code = Ref_Table.Code ;
 INTO CURSOR crsresult	 
BTW, I couldn't get the first select work with ALLTRIM() because VFP just ignored it. That's why I replaced it with STRTRAN().

< snip >
>
>IF try to use a SELECT SQL with a syntax like the following:
>
>
>SELECT;
> Work_Table.Code,Key_Table.Key,MAX(Ref_Table.Code);
> FROM Work_Table;
> INNER JOIN Ref_Table;
> ON Work_Table.Code=ALLTRIM(Ref_Table.Code);
> GROUP BY 1
>
>
>The result is, that I get the correct Code from Ref_Table, and a wrong Key.
>
>What's wrong with my statement?
>
>Thanks for Help
>
>Agnes
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform