我有下表
employee(id, pay-todate)
month_pay(employee_id(fk), hourly_pay_rate, hours_worked)
我将如何创建插入的触发器 总计(hourly_pay_rate x hours_worked)为pay-todate 只要在month_pay中添加了新行?
如果付款额为10 000或更高,我还需要减去10%
答案 0 :(得分:0)
delimiter |
CREATE TRIGGER insert_pay_trigger BEFORE INSERT ON month_pay
FOR EACH ROW BEGIN
insert into employee (id, `pay-todate`)
select NEW.employee_id,
case when NEW.hourly_pay_rate * NEW.hours_worked >= 100000
then NEW.hourly_pay_rate * NEW.hours_worked * 0.9
else NEW.hourly_pay_rate * NEW.hours_worked
end;
END
|
delimiter ;