-1
我的職責是Mysql的小數除法自動圍捕
DELIMITER $$;
CREATE FUNCTION get_approved_leaves(f_date date, t_date date,
emp_id bigint, ltp_id int)
RETURNS INT NOT DETERMINISTIC
BEGIN
DECLARE leaves_taken decimal(10,3) DEFAULT 0.000;
SELECT SUM(eld_first+eld_second)/2
INTO leaves_taken
FROM erp_apply_leaves, erp_employee_leave_debts
WHERE al_fk_employees = emp_id
AND al_from >= f_date
AND al_to <= t_date
AND al_fk_leave_type = ltp_id
AND eld_fk_apply_leaves = al_id
AND al_status = 101;
RETURN leaves_taken;
END $$;
DELIMITER ;
當我打電話
SELECT get_approved_leaves('2017-01-01','2017-12-31',18, 5) as debted
FROM `erp_employee_leave_debts` WHERE 1
它給了放:20
但這裏SUM(eld_first + eld_second)= 39 。所以我需要得到輸出= 19.5
變化'RETURNS INT'到'RETURNS DECIMAL' –