gpt4 book ai didi

mysql - 或未在 mysql 中运行的内部 case 语句

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:01 24 4
gpt4 key购买 nike

我有一个查询,我在 case 语句中放置了一个 or 语句。

or 语句由于某种原因没有运行。

例子-

 update shouts set visibility=(case when (visibility = null or visibility =1) 
then 2 else 1 end) where shout_id = 788

现在,当可见性为 null 时,它应该更新 2,而不知为何它会将字段更新为 1。

最佳答案

NULL 比较时使用 IS 运算符。因为在使用普通运算符时,将某些东西与 NULL 进行比较会导致 unknown,这不是 true

update shouts 
set visibility = case when visibility IS null or visibility = 1
then 2
else 1
end
where shout_id = 788

关于mysql - 或未在 mysql 中运行的内部 case 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24723486/

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