Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select Statement
Message
De
11/07/2003 15:25:51
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00809334
Message ID:
00809359
Vues:
20
>Everybody,
>I was wondering this is possible using a Select statement. I am using VFP 7.0. I want to add an Order column to the following Select statement. What I want in the Order column is the ranking of the record.
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	  5
Your 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.

Worst-case scenario, you could include a dummy column in your SELECT, make the resultant cursor READWRITE and then spin through the cursor and fill in the Order column:
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
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform