SELECT Pareto.Commodity, Pareto.Test_Code, ; SUM(Pareto.TtlQty) AS SumTtlQty ; FROM Pareto; GROUP BY Pareto.Commodity, Pareto. Test_Code ; ORDER BY Pareto.Commodity, SumTtlQty DESC, ; Pareto.Test_Code Returned Result Commodity Test_Code SumTtlQty Order Monitor 3501-204 13329 1 Monitor 0FUN-017 7405 2 Monitor WKS08 4919 3 Monitor 3501-203 3575 4 Monitor 3501-202 3032 5 Monitor 0FUN-018 2814 6 Monitor 0FUN-023 2426 7 Monitor 3501-218 1071 8 Monitor 3501-219 716 9 Monitor 3501-213 598 10 Motherboard WKS20 74505 1 Motherboard 0FUN-017 9712 2 Motherboard WKS12 2422 3 Motherboard 0FUN-018 2202 4 Motherboard 0FUN-016 1899 5Your example is clear, I can see what you're trying to do but I can't think of a way to do it in a VFP7 SELECT - SQL statement. The trouble is that the rows are ORDERed after the column values are filled, but the Order (rank) column value depends on the order. If it can be done with SELECT - SQL I'd think it would require some sort of sub-select, but VFP has significant limitations in what can be done with these compared to RDBMSs like SQL Server.
SELECT Pareto.Commodity, Pareto.Test_Code, ; SUM(Pareto.TtlQty) AS SumTtlQty, ; 000000 AS OrderColumn ; FROM Pareto; INTO CURSOR SomeCursor READWRITE ; GROUP BY Pareto.Commodity, Pareto. Test_Code ; ORDER BY Pareto.Commodity, SumTtlQty DESC, ; Pareto.Test_Code