Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting to VFP9 SQL
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01005624
Message ID:
01005628
Vues:
19
This message has been marked as the solution to the initial question of the thread.
>Converting VFP6 SQL to VFP9 SQL.
>
>Assuming that there is a table called custname with three columns: custnum, address,ordernum. There is no unique key. When the folloing SQL was run in VFP6, the address associated with the max(ordernum) was returned. The address was not chosen at random. How do you code this SQL in VFP9?
>
>
>select custnum, address, max(ordernum) from cust group by custnum
>
>

Brenda,

You're mistaken that address for max(ordernum) was returned. The address was returned for the last physical record in the group which in your case happens to be record with max(ordernum). If for some reason pysical order of records didn't correspond to the ordernum you would get incorrect result. The following query with derived table should give you correct result.
select cust.custnum, cust.address, cust.ordernum from cust ;
	JOIN ( select custnum, max(ordernum) AS maxord from cust group by custnum) dt1 ;
		ON cust.custnum = dt1.custnum AND cust.ordernum  = dt1.maxord 
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform