如何将SQL CASE
语句与多个AND
组合,以便我可以检查多个条件,即
我想将region
从233
随机更改为244
shopid = 455
:
select
id,
case region
when 233 and shopid = 455 and FLOOR(RAND()*(3-1)+1) = 1 then 244
when 233 and shopid = 455 and FLOOR(RAND()*(3-1)+1) = 2 then 233
else region
end
from
table1
我收到此错误:
操作数é 233'谓词的一部分&233; AND shopid = 455'应该返回类型' BOOLEAN'但返回类型' INT'。
FYI FLOOR(RAND()*(3-1)+1)
将产生1或2
答案 0 :(得分:6)
使用其他形式的case
:
select
id,
case
when region = 233 and shopid = 455 and FLOOR(RAND()*(3-1)+1) = 1 then 244
when region = 233 and shopid = 455 and FLOOR(RAND()*(3-1)+1) = 2 then 233
else region
end
from table1