我有这样的查询:
IF( @reputation < 50
AND NEW.user_id != NEW.author_id
AND (NEW.table_code != 15
OR new.user_id != (SELECT
CASE WHEN a.related IS NULL THEN a.author_id
ELSE b.author_id END cols
FROM qanda a
LEFT JOIN qanda b ON a.related = b.id
WHERE a.id = NEW.post_id )
)
) THEN
如您所知,将首先执行子查询(SELECT
语句)。我的意思是MySQL将执行SELECT
然后评估条件。因为子查询(SELECT
语句)是括号内的。
现在我试图避免先执行该子查询。我希望MySQL首先评估所有其他条件,然后如果所有条件都是TRUE
则执行该子查询。我怎样才能做到这一点?
答案 0 :(得分:2)
怎么样:
IF @reputation < 50
AND NEW.user_id != NEW.author_id
THEN
IF NEW.table_code != 15
OR new.user_id !=
(
SELECT CASE
WHEN a.related IS NULL
THEN a.author_id
ELSE b.author_id
END cols
FROM qanda a
LEFT JOIN
qanda b
ON a.related = b.id
WHERE a.id = NEW.post_id
)
THEN