请看一下我的存储过程代码。
CREATE DEFINER=`ninjaboy`@`%` PROCEDURE `getMonthlyTotalScore`(IN ninjaId int, IN month int, IN year int)
BEGIN
DECLARE startDate DATE;
DECLARE endDate DATE;
DECLARE maxDay INTEGER;
SELECT DAY(LAST_DAY(year + '-' + month + '-01')) INTO maxDay;
SET startDate = year + '-' + month + '-01';
SET endDate = year + '-' + month + '-' + maxDay;
SELECT SUM(SCORE) FROM NINJA_ACTIVITY WHERE NINJA_ID = ninjaId AND DATE BETWEEN startDate AND endDate ORDER BY DATE;
END
测试数据:
NINJA_ACTIVITY_ID | NINJA_ID | 分数 | 日期 1 1 24 2012-05-01 2 1 36 2012-05-06 3 1 29 2012-05-11
函数调用:call getTotalMonthlyScore (1, 5, 2012)
我正在尝试根据ninjaId
.
为什么不工作?知道我哪里错了吗?