Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张这样的表:Tb_server
ID 5 6 7
tb_upload
ID 1 2 3
我需要一个可以将 Tb_server 的所有 ID 更新为的查询max(Tb_upload.ID) + 1 所以,Tb_server 上的结果应该是这样的
max(Tb_upload.ID) + 1
Tb_server ID 4 5 6
我在 shell 脚本中执行此操作,因此我可以将其max(Tb_upload.ID)作为变量。但是使用 MySQL 的查询会是什么?
max(Tb_upload.ID)
取 Tb_upload 的 max+1,即:4
使更新为:
update Tb_server set Tb_serverID= (Tb_serverID+4); // 4 is the difference here
试试这个:
UPDATE Tb_server, (SELECT @auto:=0) a SET ID = (SELECT MAX(ID) FROM Tb_upload) + (@auto:= @auto+1);