gpt4 book ai didi

php - mysql insert trigger 从一张表中取出数据插入到另一张表中

转载 作者:行者123 更新时间:2023-11-28 23:21:35 25 4
gpt4 key购买 nike

下面是我的用户月薪表

+-------+------------+
|user_id|user_salary |
+-------+------------+
| 6 | 10000 |
+-------+------------+

这是我的每日考勤表

+-------------+---------+------+-------+---------------+-------+
|attendance_id| user_id |name |present|attendance_date| wages |
+-------------+---------+------+-------+---------------+-------+
| 1 | | 6 | parth| P |2016-12-16 | 350 |
+-------------+---------+------+-------+---------------+-------+

上面是我的工资和出勤表,我想根据月薪插入每天的工资并使用下面的触发器插入到出勤表是我的触发器代码。我想要 per day=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())))

最佳答案

您在 BEFORE INSERT ON 行中忘记了命令 CREATE

一个可行的例子是:

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 ;

关于php - mysql insert trigger 从一张表中取出数据插入到另一张表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41390989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com