我想达到这样的境界:
当插入数据时,它将检查一个日期列,将其与当前日期进行比较,并将某些内容写入另一列。例子:
Today 27/08/2018
Date 27/08/2018
Result: Same Day
Today 27/08/2018
Date 26/08/2018
Result: Before Today
Today 27/08/2018
Date 28/08/2018
Result: After Today
我试过了,但不起作用:
//CREATE TRIGGER trigger_update_status_before_insert
BEFORE INSERT
ON tablex
FOR EACH ROW BEGIN
IF (NEW.date < CURDATE()) THEN
SET NEW.status = 'Before Today'
END IF
IF (NEW.date = CURDATE()) THEN
SET NEW.status = 'Same Day'
END IF
IF (NEW.date > CURDATE()) THEN
SET NEW.status = 'After Today'
END IF
END;//
phpmyadmin分隔符://
1条答案
按热度按时间s5a0g9ez1#
创建mysql trigger@p.campbell的答案解决了这个问题。我刚刚删除了半列,它的工作。