gpt4 book ai didi

mysql - 错误 1193 (HY000) : Unknown system variable while Creating a trigger

转载 作者:行者123 更新时间:2023-11-29 08:48:13 24 4
gpt4 key购买 nike

大家好,我打算为 MySQL 表创建一个触发器,以便在将值插入到表中后,列 exp_sales 设置为 qnty_received 值 * sell_price 但我我收到此错误:

ERROR 1193 (HY000): Unknown system variable 'exp_sales'

这是我的查询:

delimiter $$
Create trigger tsales after insert on Store_info_table
for each row
set exp_sales = qnty_received * selling_price;
END$$

问题是什么?创建触发器的最佳方法是什么,以便在插入数量和销售价格后,exp_sales(Total) 字段更新为正确的值?

最佳答案

如果我理解正确的话,exp_sales 是您要更新的列名称:

delimiter $$
Create trigger tsales after insert on Store_info_table
for each row
update Store_info_table
set exp_sales = NEW.qnty_received * NEW.selling_price
where id = NEW.id;
END$$

更好的方法是使用 INSERT INTO ON DUPLICATE KEY UPDATE

INSERT INTO table_name(...)VALUES(...) 
ON DUPLICATE KEY SET exp_sales = qnty_received * selling_price;

关于mysql - 错误 1193 (HY000) : Unknown system variable while Creating a trigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005879/

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