mysql触发器的多个if子句

vof42yt1  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(297)

我想达到这样的境界:
当插入数据时,它将检查一个日期列,将其与当前日期进行比较,并将某些内容写入另一列。例子:

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分隔符://

s5a0g9ez

s5a0g9ez1#

创建mysql trigger@p.campbell的答案解决了这个问题。我刚刚删除了半列,它的工作。

相关问题