我准备了一个更新之前的触发器,我在其中编码了层次关系:
CREATE DEFINER=`%`@`%` TRIGGER setToClosed
BEFORE UPDATE ON issues
FOR EACH ROW
BEGIN
declare project_id1 int;
set @project_id1 = (select id from projects where name = 'XXX');
IF (new.done_ratio=100) THEN
IF (new.project_id = @project_id1) THEN
SET new.status_id=4;
ELSEIF new.project_id in (
select id
from (select * from projects) projects_sorted,
(select @pv := @project_id1) initialisation
where find_in_set(parent_id, @pv) > 0
and @pv := concat(@pv, ',', id)) THEN
SET new.status_id=4;
ELSE
SET new.status_id=5;
END IF;
END IF;
END
我想问为什么ELSEIF
未达到?我已经测试了来自ELSEIF
ant的独立查询,它返回了id列表。
在status_id
查询中ELSEIF
出现的行更改后,触发器会进入ELSE
。
我该怎么办?