你能帮我找到一个包括两个表的触发查询吗?

Can you help me in finding a trigger query including both tables?

我有 2 tables labspatientslabs 属性为 lab_idpositivenegativepatients 属性为 lab_idtest_result.

如果 patients 中插入的 test_result 是 [=14=,我想创建一个触发器来增加 labs table 中的 positive ] 和 lab_id 相同,或者如果 patients 中插入的 test_resultnegative,则 labs 中的 negative 的增量计数 table和 lab_id 相同。

对不起。我没有测试这个,因为 mysql 不存在。

不过我相信这会对你有所帮助。

Update: Error's been fixed

CREATE OR REPLACE TRIGGER trg_after_insert_patients  
AFTER INSERT ON patients FOR EACH ROW  
BEGIN  
  UPDATE labs
  SET 
    positive = CASE WHEN NEW.test_result LIKE 'positive' THEN positive + 1 ELSE positive END,
    negative = CASE WHEN NEW.test_result LIKE 'negative' THEN negative + 1 ELSE negative END
  WHERE lab_id = NEW.lab_id;
END;//