更新多行mysql [英] Update Multiple Rows mysql
本文介绍了更新多行mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子tbl
|id|points|
1 15
2 35
3 445
4 42
现在,如果我有一个像这样的数组
Now if i have an array like
array (2=>10,3=>825,4=>48)
我想更改点,以使tbl
看起来像这样.
And i want to change the points so that the tbl
looks like this.
|id|points|
1 15
2 10
3 825
4 48
我可以使用多个查询来更改值,但是任何人都可以通过一个查询来演示如何执行此操作吗?
I can change the values using multiple queries but can anyone show how to do this with one single query ?
推荐答案
使用case语句...
Use a case statement...
Update tbl
set points = CASE
WHEN ID = 1 then 05
when ID = 2 then 10
when ID = 3 then 825
when ID = 4 then 48 END
正在工作的小提琴: http://sqlfiddle.com/#!9/6cb0d/1/0
这篇关于更新多行mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文