Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
存储过程MYSQL中的减法_Mysql - Fatal编程技术网

存储过程MYSQL中的减法

存储过程MYSQL中的减法,mysql,Mysql,我想看看你是否能帮我,我已经有很多次不使用Mysql了,现在我遇到了一些困难,我需要减去一个量,然后它就会累积起来,我在一个存储过程中这样做: 我希望它显示如下: CREATE DEFINER=`root`@`localhost` PROCEDURE `balance`( in pclient int ) BEGIN declare vbalance decimal(10,2); declare vamount decimal(10,2); SELECT amo

我想看看你是否能帮我,我已经有很多次不使用Mysql了,现在我遇到了一些困难,我需要减去一个量,然后它就会累积起来,我在一个存储过程中这样做:

我希望它显示如下:

CREATE DEFINER=`root`@`localhost` PROCEDURE `balance`(
    in pclient int
)
BEGIN
    declare vbalance decimal(10,2);
    declare vamount decimal(10,2);
    SELECT amount + amount * percent into vbalance FROM credit where amount>0 and id_client= pclient;
    select 
        date, 
        if(amount>0,amount + amount * percent,amount) amount,
        vbalance + amount monto
    from 
        credit 
    where 
        id_client=pclient
        and id>=(select max(id) id from (SELECT * FROM credit where amount>0 and id_client=pclient) a);
        
END