我有两个名为" case"和出勤分别有四列:
cases-
id empid reaction date_t
1 EMP12654 interested 2017-09-22
attendance-
id empid logintime logouttime date_t flag workinghours call_att
1 EMP12654 00:14:49 05:14:49 2017-09-18 set 6 1
我想要做的是在案例表上创建一个触发器来更新考勤表的call_att列和案例表的反应栏中的条目数,这是我到目前为止所尝试的
CREATE DEFINER=`root`@`localhost` TRIGGER `number_call`
AFTER INSERT ON `cases` FOR EACH ROW
BEGIN UPDATE attendance set call_att=call_att +1
WHERE empid=new.empid AND date_t=new.date_t; END
但这似乎不起作用。我对触发器很陌生。
答案 0 :(得分:1)
试试这个
CREATE TRIGGER number_call
AFTER INSERT ON cases
FOR EACH ROW
BEGIN
UPDATE attendance set call_att=(select count(*) from cases where empid=NEW.empid )
date_t=NEW.date_t;
END