以下是我的用户月薪表
+-------+------------+
|user_id|user_salary |
+-------+------------+
| 6 | 10000 |
+-------+------------+
这是我的每日出勤表
+-------------+---------+------+-------+---------------+-------+
|attendance_id| user_id |name |present|attendance_date| wages |
+-------------+---------+------+-------+---------------+-------+
| 1 | | 6 | parth| P |2016-12-16 | 350 |
+-------------+---------+------+-------+---------------+-------+
以上是我的工资和考勤表,我想按月工资插入每日工资,并使用下面的触发器插入考勤表是我的触发代码。我想每天= monthly_salary / days_in_month并插入出勤工资表。
trigger wages before insert on attendance
for each row
set NEW.wages=(select user_salary from salary where user_id=NEW.user_id)/(SELECT DAY(LAST_DAY(now())))
答案 0 :(得分:1)
您忘记了CREATE
行中的BEFORE INSERT ON
命令。
一个工作的例子是:
DELIMITER $$
CREATE TRIGGER `trigger` BEFORE INSERT ON `attendance`
FOR EACH ROW
BEGIN
SET NEW.room = (SELECT user_salary from salary where user_id=NEW.user_id)/(SELECT DAY(LAST_DAY(now())));
END $$
DELIMITER ;
答案 1 :(得分:0)
DELIMITER $$
CREATE TRIGGER `trigger` BEFORE INSERT ON `attendance`
FOR EACH ROW
BEGIN
SET NEW.wages = (SELECT user_salary from salary where user_id = NEW.user_id)/(SELECT DAY(LAST_DAY(now())));
END $$
DELIMITER ;