sql server 将序号更新到指定的列

## 根据参照表table2的id顺序排序后生成rn排序号,然后根据关系字段column匹配更新排序号到table1的order_num。

update t1 set t1.order_num = t.rn
from table1 t1
join (select *,rn = ROW_NUMBER() OVER(ORDER BY id) from table2)t on t1.column = t.column

posted @ 2019-10-14 18:21  落笔画秋枫  阅读(673)  评论(0编辑  收藏  举报