我想知道是否可以从不同的其他列中的值更新一列...类似于:
UPDATE table
SET column1 = CASE column2,column3
WHEN column2 == test AND column3 == 1 THEN 100
WHEN (column2 LIKE %test1% OR column2 LIKE %test2%) AND column3 == 2 THEN 50
ELSE 0
END
感谢您的回答!
编辑:回答可能遇到同样问题的其他人:
UPDATE table
SET column1 = CASE
WHEN column2 = test AND column3 = 1 THEN 100
WHEN (column2 LIKE '%test1%' OR column2 LIKE '%test2%') AND column3 = 2 THEN 50
ELSE 0
END
答案 0 :(得分:1)
在案例之后删除“column2,column3”并尝试关注事物,
UPDATE table
SET column1 = CASE WHEN column2 == test AND column3 == 1 THEN 100
WHEN (column2 LIKE '%test1%' OR column2 LIKE '%test2%') AND column3 == 2 THEN 50
ELSE 0
END
以下是指导您了解CASE声明的更多信息的链接: http://dev.mysql.com/doc/refman/5.0/en/case.html