create table houses
(
houses_id int(10) not null auto_increment,
goods_id varchar(36),
goods_type varchar(10),
goods_name varchar(20),
goods_amount int,
sh_id varchar(10),
goods_sel_price decimal(12,2),
house_goods_price decimal(12,2),
primary key (houses_id)
);
①求计算 house_goods_price(金额) = goods_sel_price(单价) 乘 goods_amount(数量)
②当数量goods_amount字段发生改变时候 更新 house_goods_price值
求简单做法。
DELIMITER $$
DROP TRIGGER IF EXISTS houses_tgr$$
CREATE TRIGGER `houses_tgr`
BEFORE UPDATE
ON `houses`
FOR EACH ROW
BEGIN
IF (OLD.goods_amount != NEW.goods_amount) THEN
OR (OLD.goods_sel_price != NEW.goods_sel_price) THEN
SET NEW.house_goods_price= NEW.goods_sel_price * NEW.goods_amount;
END IF;
END$$