如果我分别创建这两个MySQL触发器,则执行ok。但我无法将它们组合起来,以便能够将持续时间乘以x率。
DROP TRIGGER IF EXISTS deduct_balance
;
CREATE DEFINER = root
@ localhost
TRIGGER deduct_balance
更新后transactions
对于每一行
SET @Rate =(SELECT rate FROM languages WHERE languages.idlanguages = contracts.languages_idlanguajes);
DROP TRIGGER IF EXISTS deduct_balance
;
CREATE DEFINER = root
@ localhost
TRIGGER deduct_balance
更新后transactions
对于每一行
UPDATE合约SET balance
= balance - (UNIX_TIMESTAMP(NEW.end_date) - UNIX_TIMESTAMP(OLD.start_date))/ 60
contract.idcontracts = new.contracts_idcontracts
组合(我得到错误)
DROP TRIGGER IF EXISTS deduct_balance
;
CREATE DEFINER = root
@ localhost
TRIGGER deduct_balance
更新后transactions
对于每一行
SET @Rate =(SELECT rate FROM languages WHERE languages.idlanguages = contracts.languages_idlanguajes);
UPDATE合约SET balance
= balance - (UNIX_TIMESTAMP(NEW.end_date) - UNIX_TIMESTAMP(OLD.start_date))/ 60;
contract.idcontracts = new.contracts_idcontracts
有什么想法吗?
我收到此错误 错误 咨询SQL:
UPDATE contract SET balance
= balance - (UNIX_TIMESTAMP(NEW.end_date) - UNIX_TIMESTAMP(OLD.start_date))/ 60;
MySQL ha dicho:Documentación
答案 0 :(得分:0)
它以这种方式工作:
更新合同
SET balance
= balance - (((UNIX_TIMESTAMP(NEW.end_date) - UNIX_TIMESTAMP(OLD.start_date))/ 60)*(SELECT语句FROM语言WHERE languages.idlanguages = new.languages_idlanguages))
contract.idcontracts = new.contracts_idcontracts