2つのクエリが次の値を返すプロシージャを作成しました
aとb
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 ;