34,594
社区成员
发帖
与我相关
我的任务
分享
if exists(select * from sysobjects where [name]='tb')
drop table tb
go
create table tb
(
id1 varchar(50),
id2 int
)
go
insert into tb(id1,id2)
(
select '0001',1 union
select '0002',2 union
select '0003',3 union
select '0004',4 union
select '0005',5
)
go
select * from tb
go
select top 2 IDENTITY(INT,1,1) as num,* into #test from tb
go
select top 1 id1,id2 from #test order by num desc
go
id1 id2
-------------------------------------------------- -----------
0002 2