Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Percent of total help
Message
 
 
À
12/05/2005 09:10:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01012865
Message ID:
01013389
Vues:
12
SELECT account, classcode, SUM(amount) AS subtotal ;
	FROM mytable ;
	GROUP BY account ;
	INTO CURSORS crsST


SELECT mt.account, mt.classcode, mt.amount, ROUND(mt.amount/st.subtotal,2) AS percentage 	
	FROM mytable mt ;
	JOIN crsST st ON st.account = mt.account ;
		AND st.classcode = mt.classcode ;
	INTO CURSOR crsResult
>
>How to create the formula to calculate the percentage out of the total in general format can be used all along ? from mytable.dbf
>
>account amount classcode percentage
>
>11111 100 AAAAA 0.16
>11111 200 AAAAA 0.34
>11111 300 AAAAA 0.50
>---------------
>subtotal 600
>
>11111 100 BBBBB 0.16
>11111 200 BBBBB 0.34
>11111 300 BBBBB 0.50
>---------------
>subtotal 600
>
>
>22222 200 CCCCC 0.25
>22222 200 CCCCC 0.25
>22222 400 CCCCC 0.50
>--------------
>subtotal 800
>
>22222 200 DDDDD 0.25
>22222 200 DDDDD 0.25
>22222 400 DDDDD 0.50
>--------------
>subtotal 800
>
>I got the columns account , amount but need to calculate the percentage but be carefull , each time the account changes the formula of percentage should changed accordingly.
>
>In addition to yesterday, instead of GROUPING by Account only, it's also GROUPING by classcode.
>
>how do you fix this codes:
>
>
>SELECT account, SUM(amount) AS subtotal ;
>	FROM mytable ;
>	GROUP BY account ;
>	INTO CURSORS crsST
>
>SELECT mt.account, mt.amount, ROUND(mt.amount/st.subtotal,2) AS percentage 	
>	FROM mytable mt ;
>	JOIN crsST st ON st.account = mt.account ;
>	INTO CURSOR crsResult
>
>
>Thanks in advance,
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform