我的问题太简单了(我想),下面是我尝试删除别名的触发器示例。我不知道自己在做什么错,只是做对了。

DELIMITER @
CREATE TRIGGER StartOfShift BEFORE INSERT ON shift
FOR EACH ROW
BEGIN
IF(NEW.CashierCode NOT IN ( SELECT w.EmployeeID FROM WorksOn as w
JOIN shop AS s ON w.ShopID = s.ShopID
JOIN CashMachineCode AS c ON s.ShopID = c.ShopID
WHERE c.CashMachineCode = NEW.CashMachineCode ))
THEN SET NEW.CashierCode = NULL;
END IF;
END;

最佳答案

以下应该是您要寻找的:

DELIMITER @
CREATE TRIGGER StartOfShift BEFORE INSERT ON shift
FOR EACH ROW
BEGIN
    IF(NEW.CashierCode NOT IN (
        SELECT WorksOn.EmployeeID FROM WorksOn
            JOIN shop ON WorksOn.ShopID = shop.ShopID
            JOIN CashMachineCode ON shop.ShopID = CashMachineCode.ShopID
            WHERE CashMachineCode.CashMachineCode = NEW.CashMachineCode )
    ) THEN
        SET NEW.CashierCode = NULL;
    END IF;
END@
DELIMITER ;

关于mysql - 帮助从MySQL触发器中删除别名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6460801/

10-13 02:34