1

IFステートメントで2つの条件を指定しようとしています...以下の2つのトリガーは構文エラーを示していませんが、機能していません。

トリガー: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 ((condition) && (condition))

4

2 に答える 2

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 ) =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 
于 2013-03-15T15:13:39.757 に答える
0

この構文で試すことができます

IF condition1
IF condition2
BEGIN
..
END
于 2013-03-15T14:36:31.890 に答える