我做了一个程序,其中两个查询返回值
甲和乙
a和b的减法是c
c = a-b;
如果 c 的值为正,则程序返回正确的值,如果 c 的值为负,则程序返回 NULL。
这是我的程序。
DELIMITER $$
USE `db`$$
DROP PROCEDURE IF EXISTS `getOutStandingBalance`$$
CREATE DEFINER=`root`@`%` PROCEDURE `getOutStandingBalance`(OUT Total DOUBLE SIGNED,IN OID INT)
DETERMINISTIC
COMMENT 'A procedure'
BEGIN
DECLARE Credit DOUBLE;
DECLARE Debit DOUBLE;
SELECT SUM(transaction.Amount) INTO Credit FROM `transaction` WHERE transaction.IsDeleted=0 AND transaction.IsCredit=1 AND transaction.OID=OID;
SELECT SUM(transaction.Amount) INTO Debit FROM `transaction` WHERE transaction.IsDeleted=0 AND transaction.IsCredit=0 AND transaction.OID=OID;
SET Total = (Credit-Debit);
END$$
DELIMITER ;