gpt4 book ai didi

sql - 我的sql触发器中if语句中的多个条件

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:05 26 4
gpt4 key购买 nike

我试图在 IF 语句中给出两个条件...下面的两个触发器没有显示任何语法错误,但它们也不起作用。

触发器 :1 :

如果存在则删除触发器 forumpostTrigger ;

CREATE DEFINER = `livecomm`@`localhost` TRIGGER `forumpostTrigger` AFTER INSERT ON `forum_post`
FOR EACH
ROW BEGIN if( (

SELECT count( * )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted ) >=30
)
THEN if( (

SELECT sum( vote_count )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted ) >=15
)
THEN
INSERT INTO user_badges( uid, bedge_id, is_active )
VALUES (
new.uid, '10', '1'
);

DELETE FROM user_badges WHERE uid = new.uid AND badge_id =9;

END IF ;

END IF ;

END

触发器:2:

DROP TRIGGER IF EXISTS `forumpostTrigger` ;

CREATE DEFINER = `livecomm`@`localhost` TRIGGER `forumpostTrigger` AFTER INSERT ON `forum_post`
FOR EACH
ROW BEGIN if( (
(

SELECT count( * )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted ) >=30
) && (
(

SELECT sum( vote_count )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted
) >=15
)
)
THEN
INSERT INTO user_badges( uid, bedge_id, is_active )
VALUES (
new.uid, '10', '1'
);

DELETE FROM user_badges WHERE uid = new.uid AND badge_id =9;

END IF ;

END

如何为 if 语句提供多个条件,例如:if ((条件) && (条件))

最佳答案

DROP TRIGGER IF EXISTS `forumpostTrigger` ;

CREATE DEFINER = `livecomm`@`localhost` TRIGGER `forumpostTrigger` AFTER INSERT ON `forum_post`
FOR EACH
ROW BEGIN if( (

SELECT count( * )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted ) =3
)
THEN
INSERT INTO user_badges( uid, badge_id, is_active )
VALUES (
new.uid, '9', '1'
);

END IF ;

if( (
SELECT count( * )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted ) =30
)
THEN if( (

SELECT sum( vote_count )
FROM forum_post
WHERE uid = new.uid
AND parent_id IS NOT NULL
AND is_answer_accepted ) >=15
)
THEN
INSERT INTO user_badges( uid, badge_id, is_active )
VALUES (
new.uid, '10', '1'
);

DELETE FROM user_badges WHERE uid = new.uid AND badge_id =9;

END IF ;

END IF ;

END

关于sql - 我的sql触发器中if语句中的多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15434967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com