Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Troublesome SQL construction
Message
 
 
À
19/12/2006 17:31:58
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 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01179041
Message ID:
01179075
Vues:
13
Try (not tested)
SELECT cus.CustomerName. NVL(sz.OrderDate, {}) AS LastDate, NVL(sz.SizeName, "") AS SizeName
	FROM Customers cus 
		LEFT JOIN Orders ord ON ord.CustomerID = cus.CustomerID 
		LEFT JOIN Sizes sz ON sz.SizeValue = ord.SizeValue
	WHERE OrderDate IS NULL OR OrderDate = ( SELECT MAX(OrdeerDate) FROM Orders ord2 WHERE ord2.OrderID = ord.OrderID)
>I'm trying to build a cursor that shows all values from the parent cursor, along with the lookup value of the most recent child record. I'm running into difficulties because not all parent records have child records.
>
>For this set of data, where [Small], [Medium], and [Large] are values from a lookup table.
>
Customer1 has 3 orders; Oct 1 for 5000 [Small], Nov 1 for 12000 [Large], Dec 1 for 7000 [Medium]
>Customer2 has 0 orders;
>Customer3 has 2 orders; Nov 1 for 7000 [Medium], Dec 1 for 11000 [Large]
>Customer4 has 1 orders; Oct 1 for 4000 [Small]
>Customer5 has 0 orders;
>
>The result set should look like:
>
Customer1  Dec 1   [Medium]
>Customer2  {//}    []
>Customer3  Dec 1   [Large]
>Customer4  Oct 1   [Small]
>Customer5  {//}    []
>
>So far, my results have either wound up with 3 Customers(cutting out 2 and 5) or 8 Customers because of the duplicates. I know this shouldn't be that hard, but I'm not seeing what I missed.
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform