您的位置: 龙岩金蝶软件论坛 -> 企业管理软件区域 -> 数据库 -> sql查询时加上行号
本帖共有275个阅读者
发表帖子 发表投票 回复主题
sql查询时加上行号
尊贵身份标志
cyy275(管理员)
cyy275
头衔:社区公民
帮派:无帮无派
帖数:497
金钱:100000
积分:2248
注册时间:2017-5-8
楼主信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
sql查询时加上行号

1(建议采用),
select row_number() over (order by col1) as no,newid() as id,*
from Table1
order by col1

2,
select no=identity(int,1,1),newid() as id,*
into  #temptable From  Table1
order by col1
Select * From #temptable
Drop Table #temptable

3,
SELECT (SELECT sum(1)  FROM Table1
WHERE col1 <= a.col1) AS no, *  
FROM Table1 a


今天的努力,明天的享受!
今天的无为,明天的无助!
今天的迷茫,明天的受累!
等级:管理员 参考IP地址:*.*.*.*
2019-8-4 16:56:15
Powered by 金蝶论坛 Copyright © 2011 www.xxhcom.cn. All rights reserved.