gpt4 book ai didi

mysql - 更新工资时计算并打印新旧工资差异的触发器

转载 作者:行者123 更新时间:2023-11-30 21:50:41 24 4
gpt4 key购买 nike

Employee 表定义为 Employee(eno, ename, salary)。

写一个触发器,在更新工资时计算并打印新旧工资的差值。

我尝试了以下触发器。好像是计算差值。如何打印?

DELIMITER $$
CREATE TRIGGER t1
AFTER UPDATE ON employee
FOR EACH ROW
BEGIN
DECLARE sal_diff DECIMAL(10,2);
IF eno = new.eno THEN
IF (new.salary < old.salary) THEN
SET sal_diff = old.salary - new.salary;
ELSE
SET sal_diff = new.salary - old.salary;
END IF;
END IF;
END $$
DELIMITER ;

最佳答案

类似的东西:

DELIMITER $$
CREATE TRIGGER t1
AFTER UPDATE ON employee
FOR EACH ROW
BEGIN
DECLARE sal_diff DECIMAL(10,2);
IF new.salary < old.salary THEN
set @sal_diff = old.salary - new.salary;
ELSE
set @sal_diff = new.salary - old.salary;
END IF;
-- Use @sal_diff where you want it;
END $$
DELIMITER ;

关于mysql - 更新工资时计算并打印新旧工资差异的触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47412954/

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