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:
01249463
Vues:
18
This message has been marked as the solution to the initial question of the thread.
Try
SELECT Customer.CustomerID, Customer.CustName, Orders.OrderID, ;
			Orders.OrderDate, Orders.Destination ;
	FROM Customer ;
		INNER JOIN orders ON Orders.CustomerID = Customer.CustomerID ;
	WHERE OrderDate = ( SELECT MAX(OrderDate) FROM Orders o2 WHERE o2.CustomerID = Orders.CustomerID) 
>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
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform