社区
MS-SQL Server
帖子详情
查询时能否得到每一行的行号(标识第几行)?
eNicYao
2003-11-24 11:39:02
如题~谢谢~
...全文
50
10
打赏
收藏
查询时能否得到每一行的行号(标识第几行)?
如题~谢谢~
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
pengdali
2003-11-24
打赏
举报
回复
select (select count(*) from 表 where 你的可以标识一条记录的主键<=tem.你的可以标识一条记录的主键) rowid,* from 表 tem
pengdali
2003-11-24
打赏
举报
回复
select (select count(*) from 表 where id<=tem.id) rowid,* from 表 tem
pengdali
2003-11-24
打赏
举报
回复
内存中:
declare @表变量(iid int identity,其他列..)
insert @表变量 (其他列) select * 你的表
select * from @表变量
pbsql
2003-11-24
打赏
举报
回复
必须插入临时表
eNicYao
2003-11-24
打赏
举报
回复
谢谢,必须插入临时表吗?直接在内存中可以实现吗?
friendliu
2003-11-24
打赏
举报
回复
select identity(int,1,1) id,* into #temp from tablename
select * froom @temp where id=??
friendliu
2003-11-24
打赏
举报
回复
如果你的行有自增长的IDENTITY型的数据就可以得到。
如果没有的话,就得增加这样的一个字段才能得到第几行
txlicenhe
2003-11-24
打赏
举报
回复
http://expert.csdn.net/Expert/topic/2437/2437014.xml?temp=.67857
交流]自增号
1: 自增列 类型为:int identity(1,1) 当然也可以是bigint,smallint
eg: create table tbName(id int identity(1,1),description varchar(20))
或在用企业管理器设计表字段时,将字段设为int,将标识设为是,其它用默认即可
2: 查询时加序号:
a:没有主键的情形:
Select identity(int,1,1) as iid,* into #tmp from TableName
Select * from #tmp
Drop table #tmp
b:有主键的情形:
Select (Select sum(1) from TableName where KeyField <= a.KeyField) as iid,* from TableName a
shuiniu
2003-11-24
打赏
举报
回复
select identity(int) 行号,* into #temp from 表
select * from #temp
pbsql
2003-11-24
打赏
举报
回复
Select identity(int,1,1) id,* into #tem from table1
select * from #tem
drop table #tem
分页的sql总结
这是一个分页的sql的总结,方法简单一看就懂
Excel中RC样式引用详解(1).docx
Excel中RC样式引用详解(1).docx
oracle、mysql数据库分页
oracle、mysql数据库分页
浙大远程教育计算机基础电子表格知识题高起专作业题答案.docx
浙大远程教育计算机基础电子表格知识题高起专作业题答案.docx
理学数据库PPT课件.pptx
理学数据库PPT课件.pptx
MS-SQL Server
34,874
社区成员
254,639
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章