我尝试构建一个mysql触发器,该触发器应首先删除行,然后根据where子句将数据存储到trans_heim表中。但是我的触发器不会在表中保存任何数据。当我在底部运行查询时,数据存储在表中。
这是我的触发器...
CREATE TRIGGER heim_ID_trans_insert AFTER INSERT on resultate
FOR EACH ROW
SET @heimteam := (Select Heimteam from resultate where ID = new.ID);
DELETE FROM heim_trans where Heimteam = @heimteam;
Insert into heim_trans(ID_trans, Spieltag, Heimteam, ID)
Select a11.ID_Final, a11.Spieltag, a11.Heimteam,a11.ID from
(
SELECT
CASE
WHEN @Heimteam = Heimteam THEN @ID_before
ELSE NULL
END AS ID_Final,
Spieltag,
@Heimteam:=Heimteam as Heimteam,
@ID_before:=ID as ID
FROM
resultate
ORDER BY Heimteam, Spieltag
) as a11
join
(
Select ID from resultate
)as a12
on a11.ID = a12.ID where a11.Heimteam = @heimteam;
;