各項目の値を各グループの合計で割って、パーセンテージを計算したいと思います。
これが私のコーディングです:
SET @VARBRANCH='
MAX(IF(Branch =''A'',`data`, NULL)) AS ''A'',
MAX(IF(Branch =''B'',`data`, NULL)) AS ''B''';
DROP TEMPORARY TABLE IF EXISTS TBL_ACBR;
SET @VARBRANCH=CONCAT('CREATE TEMPORARY TABLE TBL_ACBR SELECT Prtype,SUM(data) AS Total, '
,@VARBRANCH,
' FROM(
SELECT Prtype, Branch, `data` FROM TBLGETDATAALL_1 GROUP BY Branch,Prtype) t
GROUP BY Prtype;');
PREPARE stmacbr FROM @VARBRANCH;
EXECUTE stmacbr;
DEALLOCATE PREPARE stmacbr;
SELECT * FROM TBL_ACBR;
Script above it show as the following:
Prtype Total A B
JAM 5 3 2
Jim 6 3 3
The result that i need as the following by percentage:
Prtype Total A B
Total 11 6 5
JAM 5/11 3/6 2/5
Jim 6/11 3/6 3/5