问题
I had made two tables with the following fields:
TABLE 1: "demo"
FIELD: "demoid"
FIELD: "cpid"
FIELD: "status"
TABLE 2: "sample"
FIELD: "id"
FIELD: "conid"
FIELD: "statussample"
FIELD: "date"
I want to update the status
whenever the sample table field statussample
gets changed.
The condition would be
1) `demoid` and `id` would be same and `cpid` and `conid` would be same.(if more than one values comes i want the last inserted value of `sample` using the field `date`)
How to do that?I had stuck with this..new to Trigger format
回答1:
DELIMITER //
CREATE TRIGGER sample_after_update
AFTER UPDATE
ON sample FOR EACH ROW
BEGIN
UPDATE demo
SET demoid = NEW.id,
cpid = NEW.conid
END; //
DELIMITER;
来源:https://stackoverflow.com/questions/38745441/how-to-write-trigger-with-multiple-condition-in-mysql