----SQL2005同样也是有函数的 ----SQL2000中的话举个例子 Declare @B Table(A Varchar(2),X int) Insert @B Select 'a',10 Union All Select 'b',20 Union All Select 'c',30 Union All Select 'd',40 Select * From @B ---用临时表的话肯定不是楼主想要的吧 /*Select XX=Identity(int,1,1),A Into #B From @B Select * From #B Drop Table #B */ Select XX=(Select Count(1) From @B Where X<=T.X),A From @B T ---如果X有重复的话结果就会有偏差的 /* XX A ----------- ---- 1 a 2 b 3 c 4 d(所影响的行数为 4 行) */
select identity(int,1,1) as id,A into #t from B select * from #t drop table #t
----SQL2000中的话举个例子
Declare @B Table(A Varchar(2),X int)
Insert @B Select 'a',10
Union All Select 'b',20
Union All Select 'c',30
Union All Select 'd',40
Select * From @B
---用临时表的话肯定不是楼主想要的吧
/*Select XX=Identity(int,1,1),A Into #B From @B
Select * From #B
Drop Table #B
*/
Select XX=(Select Count(1) From @B Where X<=T.X),A From @B T
---如果X有重复的话结果就会有偏差的
/*
XX A
----------- ----
1 a
2 b
3 c
4 d(所影响的行数为 4 行)
*/
select * from #t
drop table #t