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

求教mysql批量更新有关问题

WBOY
Release: 2016-06-13 13:39:32
Original
808 people have browsed it

求教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)

大概这样

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template