Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More GROUP BY problems...
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00892909
Message ID:
00892922
Vues:
14
>>I cannot figure out why my query is not grouping the way I expect (VFP8):
>>
>>
>>SELECT 0000000000+SUM(NVL(WeekShips.Shipped,0)) AS nShipped, ;
>>	0000000000+SUM(NVL(WeekSales.Sales,0)) AS WeekSales, ;
>>	0000000000+SUM(NVL(YTDSales.Sales,0)) AS YTDSales, ;
>>	ItemSetup.Retail, 0000000000+NVL(iciwhs.nOnHand,0) AS nOnHand ;
>>	FROM ItemSetup ;
>>	INNER JOIN ItemSales ON ItemSetup.cItemNo = ItemSales.cItemNo ;
>>		AND ItemSales.Category = "TRANSFER" ;
>>	LEFT JOIN WeekShips ON WeekShips.cItemNo = ItemSetup.cItemNo ;
>>	LEFT JOIN WeekSales ON WeekSales.UnitRetail = ItemSetup.Retail ;
>>	LEFT JOIN IciWhs ON iciWhs.cItemNo = ItemSetup.cItemNo ;
>>	LEFT JOIN YTDSales ON YTDSales.UnitRetail = ItemSetup.Retail ;
>>	ORDER BY ItemSetup.Retail, nOnHand ;
>>	GROUP BY ItemSetup.Retail, nOnHand ;
>>	HAVING YTDSales > 0 ;
>>	INTO CURSOR SpreadsheetResults
>>
>>
>>My resulting cursor has many records for each "retail" value! Any idea why?
>
>I presume you have multiple nOnHand values for each "retail" value, since you are also grouping on nOnHand.

No - Proper SQL syntax now requires that all non-aggregate fields appear in the 'group by' clause to define sort order for grouping (as of VFP8).

>
>I think that your ORDER BY clause is superfluous. If I remember right, it will order on the stuff in the GROUP BY clause.

I think you are right about the ORDER BY clause being redundant... I added it while grasping at straws.
Kogo Michael Hogan

"Pinky, are you pondering what I'm pondering?"
I think so Brain, but "Snowball for Windows"?

Ideate Web Site
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform