码迷,mamicode.com
首页 > 数据库 > 详细

sql server更新一列为行号

时间:2017-11-14 14:09:37      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:http   art   targe   显示行号   sele   article   blank   detail   查询   

:引用自http://blog.csdn.net/lenovouser/article/details/52281726

查询显示行号:

1 SELECT
2     row_number () OVER (ORDER BY orderby_id) AS rowNumber
3 FROM
4     table_name;

 

 

更新一列为行号:

 1 UPDATE table_name
 2 SET new_row = t1.rowid
 3 FROM
 4     (
 5             select table_pk,
 6         row_number () OVER (ORDER BY orderby_id) AS rowid
 7     FROM
 8         table_name
 9     )     
10 ) AS t1
11 WHERE
12     t1.table_pk = table_name.table_pk;

sql server更新一列为行号

标签:http   art   targe   显示行号   sele   article   blank   detail   查询   

原文地址:http://www.cnblogs.com/Summerppp/p/7831673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!