Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting most recent orders?
Message
 
 
À
21/08/2007 15:41:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01249462
Message ID:
01249464
Vues:
16
Chris,

Please see Re: MAX function Thread #1247432 Message #1247435

>I'm trying to generate a list of Customers with their most recent Orders.
>Getting the most recent Order is a simple MAX(orderdate), but how do I get the details of that one Order?
>
>Right now it's working with a three step process, but there MUST be an easier way that I'm not seeing.
>
>SELECT CustomerID, MAX(OrderDate) as OrderDate FROM Orders GROUP BY 1 INTO CURSOR LastOrder
>
>SELECT Orders.CustomerID, LastOrder.OrderID, LastOrder.OrderDate, Orders.Destination, Orders.Amount ;
>FROM Orders INNER JOIN LastOrder ON Orders.OrderID = LastOrder.OrderID and Orders.OrderDate = LastOrder.OrderDate ;
>INTO CURSOR MostRecent
>
>SELECT Customer.CustomerID, Customer.CustName, MostRecent.OrderID, MostRecent.OrderDate, MostRecent.Destination ;
>FROM Customer INNER JOIN MostRecent ON Customer.CustomerID = MostRecent.CustomerID
>
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