问题描述:从excel中导入大量数据到mysql,自增id没有按顺序自增,中间有很多跳过了,由于数量巨大,不想重新导入
解决思路:按照id或者时间按从小到大排序==>获取行号==>用行号替换原来的id
sql语句:update tab as t1 join (select id,(@rowno:=@rowno+1) as rowno from tab a,(select (@rowno:=0)) b order by a.id) as t2 SET t1.id=t2.rowno WHERE t1.id=t2.id;