MySQL IN(............) 里面有大量数据

我要更新一表格,其被Update的数量非常非常的多

update ybtbo set TBNewFlag=1 where AtTBOID IN (698,699.............)

我这(689,699,700.............. ) 约有4000到5000个
我少数用100多个是没问题的

我有想到的是,将这些数组切500个update一次,但我不知道怎么切

目前将这些数组传到了temstr=(689,699,700...............)

希望能提供较好的方式来update这个大表格

这么多In的数据,最好还是用其他条件来取代In

可以试一下用存储过程批量更新

in里面的id如果是连续的就直接id>xxx。如果是不连续的id的话,分多条sql去更新,我觉得快速的办法就是在excel中去组装多条sql,把id拷贝到excel的一列里面去后面不说你也知道怎么做了。

drop procedure if exists procUpdate;
CREATE PROCEDURE procUpdate()
begin
DECLARE minid INT;
DECLARE maxid INT;
DECLARE currentid INT;
DECLARE endid INT;
DECLARE seed INT;
set seed=500;
set minid = 698;
set maxid = 你的最大值;
select minid,maxid;
set currentid=minid;
while currentid<=maxid
do
if currentid+seed>maxid then
set endid=maxid;
else
set endid=currentid+seed;
end if;
update ybtbo set TBNewFlag=1 where AtTBOID = minid
between currentid and endid;
set currentid=endid+1;
end while;
end;
CALL procUpdate;
drop procedure procUpdate;

评论有字数限制。所以再次回答一次,上面是存储过程,没有你的数据库,不知道能不能行;如果不能执行,你再百度一下,改一下

where AtTBOID IN (498,499.............) or AtTBOID IN (598,599.............) or AtTBOID IN (698,699.............)

传递参数用list,sql语句里foreach循环list,也不用分割啊

最好用sql查询出需要更新的主键update table set a=** where pkvalue in(select pkvalue from table )

给你一个思路,AtTBOID 建立索引,in里面的放入临时表,两个表做inner join,结果就是你要的。

首先创建一张临时表AtTBOID_Tmp,用来存储in 里面的id,字段名也叫做AtTBOID吧
然后执行下面的语句就可以了
update ybtbo t1,AtTBOID_Tmp t2 set t1.TBNewFlag=1 where t1.AtTBOID = t2.AtTBOID;