这是我的存储过程:
CREATE PROCEDURE `getAttritionData`(
IN `supid` BIGINT,
IN `from_date` DATE,
IN `to_date` DATE,
OUT `attr_rate` FLOAT,
OUT `TERM_EMP_CNT` INT
)
DETERMINISTIC
BEGIN
DECLARE i INTEGER DEFAULT 0;
DECLARE CNT_EMP INTEGER DEFAULT 0;
DECLARE TOT_EMP INTEGER DEFAULT 0;
DECLARE AVG_HCOUNT INTEGER DEFAULT 0;
SELECT count(employee_id) INTO TERM_EMP_CNT FROM employee
WHERE term_date between from_date and to_date AND app_role=1;
WHILE from_date<=to_date DO
SELECT COUNT(EMPLOYEE_ID) INTO CNT_EMP FROM employee
WHERE sup_id=supid AND doj<from_date
AND (term_date>from_date OR term_date='0000-00-00') AND app_role=1;
SET from_date=date_add(from_date, INTERVAL 1 DAY);
SET i=i+1;
SET TOT_EMP = TOT_EMP + CNT_EMP;
END WHILE;
SET AVG_HCOUNT=(TOT_EMP/i)*365/12;
SET attr_rate = TERM_EMP_CNT/AVG_HCOUNT;
END
我想要attr_rate
一个数组,它有 1 个键和另一个值,例如:
attr_rate[6-2015]=3.5
attr_rate[7-2015]=6.2
attr_rate[8-2015]=3.3
如何在 MySQL 存储过程中声明数组?
存储过程不支持数组,可以使用临时表。
试试这个代码:
希望你的问题能得到解决。