日期:2014-05-17 浏览次数:20619 次
declare  @table1 table (id int)
insert into @table1
select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 ;
with
a as 
(
    select top(5)id from @table1
)
select top(1)id from a order by id desc
select top(1)id from( select top(5)id from @table1) a order by id desc
declare  @table1 table (id int)
insert into @table1
select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 ;
with
a as 
(
    select top(5)id from @table1 order by id
)
select top(1)id from a order by id desc
/*
(8 行受影响)
id
-----------
5
(1 行受影响)
*/