目前主要有2种方法
1,select * into #tmp from table
alter #tmp add cnt identity(1,1)
select * from #tmp
2,有一个可以唯一区分的列或列组合
select *,(select count(*) from table t2 where t2.id<=t.id) as cnt from table t
1,select * into #tmp from table
alter #tmp add cnt identity(1,1)
select * from #tmp
2,有一个可以唯一区分的列或列组合
select *,(select count(*) from table t2 where t2.id<=t.id) as cnt from table t
select (select count(*)+1 from mm a where a.主键>主键 and n1>50) as id,name from mm where n1>50
select * from #tmp
1,select * into #tmp from table
alter #tmp add cnt int identity(1,1)
select * from #tmp
2,要有一个可以唯一区分的列或列组合
select *,(select count(*) from table t2 where t2.id<=t.id) as cnt from table t
select * from #temp
drop table #temp
SELECT * FROM #
select * from #temp
drop table #temp
alter table #A add id int identity(1,1)
select * from #A
insert #tem select name from mm where n1>50
select * from #tem
drop table #tem