Home  >  Article  >  Backend Development  >  求教mysql批量更新有关问题

求教mysql批量更新有关问题

WBOY
WBOYOriginal
2016-06-13 10:15:11930browse

求教mysql批量更新问题
我想批量更新数据,字段值也不同
例如:
set s=1 where id=1;
set s=2 where id=3;
这种情况除了逐条更新还有更好的方法吗?
因为一次更新有可能比较多
谢谢


------解决方案--------------------
UPDATE table
SET s = CASE id
WHEN 1 THEN '1'
WHEN 3 THEN '2'
END
WHERE id IN (1,3)

大概这样

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn