Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Yet another 'Group By' question re SET EngineBehavior
Message
De
13/08/2005 12:46:55
 
 
À
13/08/2005 10:06:08
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 9
OS:
Windows XP SP1
Divers
Thread ID:
01040687
Message ID:
01040696
Vues:
15
>In moving from SET EngineBehavior 70 to SET EngineBehavior 90 , I've encountered the same difficulties mentioned numerous times in this forum regarding the special attention necessary for the GROUP BY clause. I now understand the changes that are necessary when the old code fails, and have been happily making them as necessary.
>
>However, I do have some instances where the old behavior worked very nicely, and I don't see an easy solution using the new behavior:
>
SELECT *, SUM(AMT) AS TOTAMT FROM Orders GROUP BY OrdNbr
>The table "Orders", unfortunately, contains both parent records and child records. This particular selection would give me one record for each OrdNbr and all of the original fields from "Orders", so that I would, in effect, be creating the parent records (with the fields for what should have been child records containing irrelevant information.)
>
>So, is it possible to achieve the same effect using the new behavior without enumerating all the fields in the GROUP BY clause? (I can do it by enumerating the fields, but I certainly would hope not to have to do so).
>
>Thanks

Require a PK or candidate key
* supposing OrdNbr,ChildRowNbr defines a record univocal

SELECT Orders.*,TGROUP.TOTAMT;
(SELECT OrdNbr,MAX(ChildRowNbr) ChildRowNbr,SUM(AMT) TOTAMT FROM Orders GROUP BY OrdNbr) TGROUP;
JOIN Orders;
ON Orders.OrdNbr=TGROUP.OrdNbr AND Orders.ChildRowNbr=TGROUP.ChildRowNbr
or
TRY
 SET EngineBehavior 70
 SELECT *, SUM(AMT) AS TOTAMT FROM Orders GROUP BY OrdNbr
FINALLY
 SET EngineBehavior 90
ENDTRY
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform