create function getRemainInterests(p_payment_number varchar(40), p_plan_list int) returns decimal(18,2)
RETURN (
 SELECT
  ROUND(
      IFNULL(a.suminterest, 0) - SUM(IFNULL(lrp.interest, 0)),
      2
    ) 
 
FROM
  lc_rent_plan lrp 
  LEFT JOIN (SELECT contract_id,payment_number,SUM(interest) AS suminterest FROM lc_rent_plan where payment_number=p_payment_number GROUP BY payment_number) a ON a.payment_number=lrp.payment_number
WHERE lrp.payment_number = p_payment_number 
  AND  lrp.plan_list <= p_plan_list 
GROUP BY lrp.payment_number
 );

