在触发器中如何获得多个条件检查,如
CREATE TRIGGER record_big_order AFTER INSERT ON orders
BEGIN
IF new.value > 1000000 THEN
INSERT INTO big_orders (customer_name, salesman_id, value,Mark)
VALUES (new.customer_name, new.salesman_id, new.value,'1')
END IF;
IF new.value > 2000000 THEN
INSERT INTO big_orders (customer_name, salesman_id, value,Mark)
VALUES (new.customer_name, new.salesman_id, new.value,'2')
END IF;
IF new.value > 3000000 THEN
INSERT INTO big_orders (customer_name, salesman_id, value,Mark)
VALUES (new.customer_name, new.salesman_id, new.value,'3')
END IF;
END;
答案 0 :(得分:2)
您可以尝试以下INSERT语句 -
INSERT INTO big_orders (customer_name, salesman_id, value,Mark)
VALUES (new.customer_name, new.salesman_id, new.value,
CASE WHEN new.value > 3000000 THEN '3'
WHEN new.value > 2000000 THEN '2'
WHEN new.value > 1000000 THEN '1' END)