这是我在mysql中的更新查询
UPDATE userentries
SET User_Rank =
(
SELECT
urc.rankofentr as User_Rank
from UserRankingsys as urc
WHERE urc.entryid = userentries.id
LIMIT 1
)
where userentries.id = 15
我想检查该部分返回的值
(
SELECT
urc.rankofentr as User_Rank
from UserRankingsys as urc
WHERE urc.entryid = userentries.id
LIMIT 1
)
如果此子查询返回的值大于我要设置的值102,我该怎么做
最佳答案
您可以使用CASE
SELECT case urc.rankofentr when > 20 then 20
else urc.rankofentr
end as User_Rank
from UserRankingsys as urc
WHERE urc.entryid = userentries.id
LIMIT 1
为你的sql
UPDATE userentries
SET User_Rank =
(
SELECT case urc.rankofentr when > 20 then 20
else urc.rankofentr
end as User_Rank
from UserRankingsys as urc
WHERE urc.entryid = userentries.id
LIMIT 1
)
where userentries.id = 15;
关于mysql - 我要检查子查询的值如何检查?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34806187/