我创建了一个存储过程,使用该技术的ID和预期年份作为该存储过程的输入,以计算每个技术人员的工作数量,但我坚持使用。 。 。 如何在该过程中获取输出数组,以便例如 稍后可以在php代码中使用它 。 这是我的存储过程:
didSet
答案 0 :(得分:1)
如果要执行多个查询,则需要创建一个临时表来保存中间结果,然后将SELECT * FROM thattemporarytable
设置为过程中最后要做的事情之一。
像这样...
BEGIN
DROP TEMPORARY TABLE IF EXISTS `blah` ( num INT );
CREATE TEMPORARY TABLE `blah` ( num INT );
SET @x := 1;
WHILE @x<13 DO
INSERT INTO blah (num)
SELECT COUNT(work.workType)
FROM work
WHERE year(workDate)=yearInput
AND work.technicianID = id
AND month(workDate)= @x
;
SET @x := @x+1;
END WHILE;
SELECT * FROM blah;
DROP TEMPORARY TABLE blah;
END
或者,如果您可以将其作为单个查询进行管理,则正常选择应该可以:
BEGIN
SELECT COUNT(work.workType)
FROM work
WHERE year(workDate)=yearInput
AND work.technicianID = id
AND month(workDate) BETWEEN 1 AND 12
;
END
答案 1 :(得分:0)
我已使用临时表将数据存储到其中,然后使用select语句将其发布并在过程结束时删除临时表
DROP PROCEDURE `work_count`;
CREATE DEFINER=`root`@`localhost` PROCEDURE `work_count`(IN `id` INT, IN `yearInput` INT) NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER
BEGIN
SET @x := 1;
WHILE @x<13 DO
SELECT COUNT(work.workType)
FROM work
WHERE year(workDate)=yearInput
AND work.technicianID = id
AND month(workDate)= @x;
SET @x := @x+1;
END WHILE;
END