本文介紹兩種批量更新數據方法
數據準備
create table account
(
id int auto_increment
primary key,
balance int not null
);
insert into account(balance) values (10),(20);

表中數據
1
update account t1 inner join (select 1 a,5 b union all select 2 a,15 b ) t2 set t1.balance = t2.b where t1.id = t2.a;

執行后結果
2
update account t set t.balance = case when id =1 then 20 when id =2 then 20 end where id in (1,2)

執行后結果
附:
兩種方法受sql語句長度限制,和線程內存大小限制,需根據服務器情況選擇批量更新條數!