我有表赞
OldTbl
ID Name Age
12 name1 15
544 name2 15
2544 name3 15
我需要使用查询(ID是主键)来制作这样的ID
ID Name Age
1 name1 15
2 name2 15
3 name3 15
任何想法?
答案 0 :(得分:4)
您可以在查询中执行此操作:
select row_number() over (order by id) as id, name, age
from table t;
如果要更新表格,请执行以下操作:
with toupdate as (
select row_number() over (order by id) as new_id, t.*
from table t
)
update toupdate
set id = new_id;