我想通过 mysql 存储过程中的交叉表汇总总计和小计。我会在我的脚本中添加小计。
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;
它上面的脚本显示如下:
Prtype Total A B
JAM 5 3 2
Jim 5 3 3
我需要的结果如下:
Prtype Total A B
JAM 5 3 2
Jim 5 3 3
Total 10 6 5