标签:
# group by 加子句 with rollup 用法
DELIMITER $$
USE `bank`$$
DROP PROCEDURE IF EXISTS `dearSUM`$$
CREATE
PROCEDURE `bank`.`dearSUM`(
IN i_pass CHAR(6)
)
BEGIN
IF (i_pass = "123456") THEN
SELECT tradeType, SUM(tradeMoney) FROM tradeinfo WHERE tradeDate
GROUP BY tradeType WITH ROLLUP;
END IF;
END$$
DELIMITER ;
#用其他方法来实现group by 加子句 with rollup 用法的效果
DELIMITER $$
USE `bank`$$
DROP PROCEDURE IF EXISTS `dearSUM`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `dearSUM`(
IN i_pass CHAR(6)
)
BEGIN
IF i_pass = "123456" THEN
SELECT tradeType AS "交易类型" ,SUM(tradeMoney) AS "交易总数"
FROM tradeinfo
GROUP BY tradeType
UNION
SELECT "总计", SUM(tradeMoney)
FROM tradeinfo ;
END IF;
END$$
DELIMITER ;
CALL dearSUM("123456");
标签:
原文地址:http://www.cnblogs.com/lxh1076/p/5698048.html