Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Yet another 'Group By' question re SET EngineBehavior
Message
From
13/08/2005 17:31:30
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP1
Miscellaneous
Thread ID:
01040687
Message ID:
01040731
Views:
14
Sergey --

Unfortunately, I don't seem to be getting the results I expect. I still get one record for every original record I selected from "Orders", with the total column added at the end.

What I'm looking for, and get with 70, is that I get one record for each unique OrdNbr in "Orders", with the total column added at the end. Thus, I get the same number or records as you obtained within your sub-query. It looks like the JOIN you suggested each of the records from my original table with the single row from the sub-query; I want one row (and I don't care which one) from the original table for each row in the sub-query.

Thanks yet again ...

Jim


>Jim,
>
>Try
SELECT Orders.*, tot.TOTAMT ;
>  FROM Orders ;
>    JOIN (SELECT OrdNbr, SUM(AMT) AS TOTAMT FROM Orders GROUP BY OrdNbr) tot ;
>  ON tot.OrdNbr = Orders.OrdNbr
>
>
>>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).
>>
Jim Nelson
Newbury Park, CA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform