gpt4 book ai didi

mysql - 如何将查询结果存储到变量中?

转载 作者:行者123 更新时间:2023-11-29 20:27:51 24 4
gpt4 key购买 nike

这是我的代码:

BEGIN     
IF (new.edited_id IS NULL) THEN
IF (SELECT 1 FROM users WHERE id = new.author_id AND IFNULL((active & b'1000000' > 0), 0) < 1) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "you cannot ask anymore";
ELSEIF (SELECT 1 FROM users WHERE id = new.author_id AND IFNULL((active & b'10000000' > 0), 0) < 1) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "you cannot answer anymore";
END IF;
ELSE
IF (SELECT 1 FROM users WHERE id = new.author_id AND IFNULL((active & b'100000000' > 0), 0) < 1) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "you cannot edit anymore";
END IF;
END

如您所见,这些内部 IF 语句的条件几乎相同。那么我该如何改进呢?我的意思是如何将该查询的结果存储到变量中,然后使用该变量作为条件?

最佳答案

您现在可以在 if 语句中使用变量 condition

SET @condition := (SELECT 1 FROM users WHERE id = new.author_id AND IFNULL((active & b'1000000' > 0), 0) < 1);

关于mysql - 如何将查询结果存储到变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39192970/

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