我的表是:tbl_fee_payment_history
pk_int_fph_id fk_int_student_id int_fph_amount dat_fph_date
1 1 10000 2013-12-11
2 2 5000 2013-11-11
3 1 5000 2014-12-16
4 3 5000 2013-10-19
5 4 5000 2014-01-11
我想创建一个存储过程,它将返回特定年份的总金额。
等;
call csp_fee(2013); return value as 20000.
答案 0 :(得分:0)
没有经过测试,但我希望它会起作用。
DELIMITER $$
drop procedure if exists csp_fee$$
CREATE PROCEDURE `csp_fee`(
IN in_year DECIMAL(18,2),
OUT in sum_year DECIMAL(18,2))
BEGIN
SELECT round(sum(int_fph_amount),2)
INTO sum_year
FROM tbl_fee_payment_history where
DATE_FORMAT(dat_fph_date,'%Y') = in_year;
END;
$$
DELIMITER ;