SQL增加一个数字 [英] SQL increment a number
本文介绍了SQL增加一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题:
我想根据表格增加一个数字.例如,如果一个表包含行
I want to increment a number based on a table. So for example, if a table contains row
1 1 2 3 4 4 4 5
mytable 列应该基于此递增,取上列中的 max(row) + 1.所以结果应该是这样的:
mytable column should increment based on this taking the max(row) + 1 in the above column. So the outcome should look like this:
6 6 7 8 9 9 9 10
这是目前的代码:
OPEN cur
DECLARE @WORKING_ON_ID INT
FETCH NEXT FROM cur INTO @WORKING_ON_ID
WHILE @@FETCH_STATUS = 0
BEGIN
SET @MAX_ID = @MAX_ID + 1
UPDATE
#WorkingTable
SET
ID = @MAX_ID
WHERE
ID = @WORKING_ON_ID
FETCH NEXT FROM cur INTO @WORKING_ON_ID
END
CLOSE cur
DEALLOCATE cur
你能帮我解决这个问题吗?谢谢!
Could you please help me in getting a solution to this problem. Thanks!
推荐答案
我认为你可以很容易地做到这一点:
I think you could do it easily with this:
UPDATE your_table
SET id = id + (SELECT MAX(id) FROM your_table)
这篇关于SQL增加一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文