通过 MYSQL 中的 TRIGGER 从另一个 table 插入值

inserting values from another table via a TRIGGER in MYSQL

我需要创建一个触发器当一个新的记录被添加到“计划”table,一个记录被自动创建在“结果”table。 Table“计划”有列:

Table“结果”包含列:

我附上了我的代码,但显然其中有错误

CREATE DEFINER = CURRENT_USER TRIGGER `mydb`.`Plan_AFTER_INSERT` AFTER INSERT ON `Plan` FOR EACH ROW
BEGIN
insert into results (Result, idClient, Date, idService, idEmployee)
 values ('в процессе',idClient = (Select idClient from Clients
where Clients.Groupe = Plan.New.Groupe),
NEW.Date, NEW.idService, NEW.idEmployee);
END

没关系只是你的子查询只有一行return,所以最好限制一下

DELIMITER //
CREATE DEFINER = CURRENT_USER TRIGGER `mydb`.`Plan_AFTER_INSERT` AFTER INSERT ON `Plan` FOR EACH ROW
BEGIN
insert into results (Result, idClient, Date, idService, idEmployee)
 values ('в процессе',(Select idClient from Clients
where Clients.Groupe = New.Groupe ORDER BY idClient LIMIT 1),
NEW.Date, NEW.idService, NEW.idEmployee);
END//
DELIMITER ;