Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing duplicate Columns in View's SQL
Message
 
 
À
26/06/2009 11:52:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01408243
Message ID:
01408699
Vues:
34
>Hi Naomi. I'm unclear on what "derived tables" are and would appreciate a little clarity on the following code in terms of what it represents and how it works so I can debug it if needed. As always, your help is appreciated:
>
>(1) ChildCount.CountChildren
>(2) count(distinct(ChildrenPK)) as CountChildren from Child group by 1)
>CountChildren on Parent.PK = CountChildren.ParentFK


Hi Abel,

Say, you have two tables Parent and Child and you want to retrieve information Parent - Child information + Count Of Children per parent and Max, Min value of, Say, amount field in Child per Parent.

Say, Parent is Order Header

OrderID OrderDate CustomerID

and Child is Order Details

OrderDetailID OrderID - FK ItemID Qty Price
select Parent.OrderDate, Child. ItemID, Child.Qty, Child.Price, 
OrderSummay.MinAmount, OrderSummary.MaxAmount, OrderSummary.ItemsCount 
from Parent LEFT JOIN Child on Parent.OrderID = Child.OrderID 
LEFT JOIN (OrderID, select Max(qty*Price) as MaxAmount, MIN(qty*Price) as MinAmount, 
Count(*) as ItemsCount from Child group by OrderID) OrderSummary on Parent.OrderID = OrderSummary.OrderID
The query in parenthesis aliased as OrderSummary is called Derived table. This is a technique to add certain information to the parent record and this is what you can use in your case too.

This only works in VFP9.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform