我有这个问题:
IF( 125 > (SELECT reputation FROM users WHERE id=new.user_id) OR
1 <> (SELECT active FROM users WHERE id=new.user_id)
) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "You need at least 125rep to give downvote.
And your account have to be active.";
END IF;
如何在IF
声明中改善该条件?
答案 0 :(得分:3)
我们可以合并,如下:
SELECT 1
FROM users
WHERE id=new.user_id
AND (reputation < 125 OR (active != 1 OR active IS NULL))
编辑:忽略空活动状态。