Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有三个字段,即 num1 num2 和 num3/ans 我想减去 num1 和 num2 字段,并且 ans 应该在 num3/ans 字段中,例如 num1 值为 400,num 值为 100,然后 ans/num3 字段中的值应该会自动出现
你需要这个吗?
UPDATE tbl SET num3 = num1 - num2
或者如果你想要计算字段,直接是不可能的,但是你可以使用触发器
CREATE TRIGGER MyTrigger BEFORE INSERT ON tbl FOR EACH ROW SET NEW.num3 = NEW.num1 - NEW.num2;