MySQL 触发器if语句只执行第一个 50
DELIMITER//CREATETRIGGERQuestion_01BEFOREINSERTONSCFOREACHROWBEGINIFnew.grade>=90THEN...
DELIMITER //
CREATE TRIGGER Question_01 BEFORE INSERT ON SC FOR EACH ROW
BEGIN
IF new.grade>=90 THEN
UPDATE trank SET num=num+1 WHERE division='100-90' AND cno=new.cno;
ELSEIF new.grade BETWEEN 89 AND 80 THEN
UPDATE trank SET num=num+1 WHERE division='89-80' AND cno=new.cno;
ELSEIF new.grade BETWEEN 79 AND 70 THEN
UPDATE trank SET num=num+1 WHERE division='79-70' AND cno=new.cno;
ELSEIF new.grade BETWEEN 69 AND 60 THEN
UPDATE trank SET num=num+1 WHERE division='69-60' AND cno=new.cno;
ELSEIF new.grade<60 THEN
UPDATE trank SET num=num+1 WHERE division='59-0' AND cno=new.cno;
END IF;
END//
DELIMITER ;
为什么触发器中的IF语句只判断第一个,后面ELSEIF不进行判断了 展开
CREATE TRIGGER Question_01 BEFORE INSERT ON SC FOR EACH ROW
BEGIN
IF new.grade>=90 THEN
UPDATE trank SET num=num+1 WHERE division='100-90' AND cno=new.cno;
ELSEIF new.grade BETWEEN 89 AND 80 THEN
UPDATE trank SET num=num+1 WHERE division='89-80' AND cno=new.cno;
ELSEIF new.grade BETWEEN 79 AND 70 THEN
UPDATE trank SET num=num+1 WHERE division='79-70' AND cno=new.cno;
ELSEIF new.grade BETWEEN 69 AND 60 THEN
UPDATE trank SET num=num+1 WHERE division='69-60' AND cno=new.cno;
ELSEIF new.grade<60 THEN
UPDATE trank SET num=num+1 WHERE division='59-0' AND cno=new.cno;
END IF;
END//
DELIMITER ;
为什么触发器中的IF语句只判断第一个,后面ELSEIF不进行判断了 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询