34,591
社区成员
发帖
与我相关
我的任务
分享
select *,Id=(row_number() over (order by id)) from tab
select IDENTITY(int,1,1) as id,* into # from tb
select * from #
drop table #
--为表增加序列号的方法:
create table #t
(
姓名 varchar(10) ,
语文 int
)
insert into #t(姓名 , 语文 ) values('张三',73)
insert into #t(姓名 , 语文 ) values('李四',99)
insert into #t(姓名 , 语文 ) values('王十',12)
insert into #t(姓名 , 语文 ) values('李三',34)
insert into #t(姓名 , 语文 ) values('赵六',56)
insert into #t(姓名 , 语文 ) values('目一',15)
insert into #t(姓名 , 语文 ) values('人人',100)
insert into #t(姓名 , 语文 ) values('我产',78)
select *
from #t
select (select count(1) from #t where 语文>=T.语文) as 名次,
T.*
from #t T
order by 语文 DESC
4楼说的很正确,这是sql server2005的新增功能,请运行下列语句就知道了
请在sql server 2005下运行
select row_number() over(order by name) as id
,name
,type
from sys.objects with (nolock)
select IDENTITY(int,1,1) as id,* into #tb from tb
select * from #tb
drop table #tb
go
select row_number() over(order by 排序字段) as first,fields form tb