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.
我有一个字段值 1,2,3,5,6,.... 我的问题是,当我尝试插入“2”时,当前的 2,3 增加了 1 并且 5,6 保持不变(因为 4 不存在),则需要在 2 的位置插入新值。我尝试更新查询
Update table set v1=v1+1 where v1>=newvalue
在插入新值之前。但是 5,6 也增加了 1。我不知道该怎么做。有谁知道如何处理这个,请帮助我。我有大量数据,所以无法循环更新每个值
SELECT t1.v1 + 1 AS gap FROM `table` AS t1 LEFT OUTER JOIN `table` AS t2 ON t2.v1 = t1.v1 + 1 WHERE t2.v1 IS NULL AND t1.v1 >= :newvalue ORDER BY t1.v1 ASC LIMIT 1
v1这个查询给出了插入时更新的上限:newvalue。
v1
:newvalue