触发器 - Mysql管理器

时间:2017-09-17 16:20:43

标签: mysql triggers

我创建了两个表: 1)经理 2)销售 我需要这样做; 如果经理成功销售20次,那么保费就是销售额的20%。 我这样写了,但错误在哪里?

DELIMITER $$
CREATE TRIGGER `calculate_prize_upd` AFTER UPDATE ON `students` FOR EACH ROW BEGIN

       UPDATE manager set
       goods = (SELECT COUNT(*) FROM selling WHERE manager_id = NEW.manager_id)
       WHERE id = NEW.manager_id;
       IF (goods > 20) THEN
        prize = 
        (SELECT price/0.2 FROM selling WHERE manager_id = new.manager_id);



END
$$
DELIMITER ;

1 个答案:

答案 0 :(得分:0)

我认为这应该是这样的 -

DELIMITER $$
CREATE TRIGGER `calculate_prize_upd` AFTER UPDATE ON `students` FOR EACH ROW  
BEGIN
    DECLARE @goods varchar(100)
    SET @goods = SELECT COUNT(*) FROM selling WHERE manager_id = NEW.manager_id
    IF (goods > 20) THEN
    UPDATE selling 
    SET prize = prize * 1.2 
    WHERE manager_id = new.manager_id
END
$$
DELIMITER ;