declare @ta table(ID int, name varchar(2), Content varchar(5))
insert @ta select 1, 'a', 'aa'
union all select 2, 'b', 'bb'
union all select 3, 'c', 'cc'
union all select 4, 'd', 'dd'
union all select 5, 'e', 'ee'
union all select 6, 'f', 'ff'
select * from (select top 2 * from @ta order by ID desc )ta order by id asc
ReportServer$wuxi
insert @ta select 1, 'a', 'aa'
union all select 2, 'b', 'bb'
union all select 3, 'c', 'cc'
union all select 4, 'd', 'dd'
union all select 5, 'e', 'ee'
union all select 6, 'f', 'ff'
select * from (select top 2 * from @ta order by ID desc )ta order by id asc
ReportServer$wuxi
insert @ta select 1, 'a', 'aa'
union all select 2, 'b', 'bb'
union all select 3, 'c', 'cc'
union all select 4, 'd', 'dd'
union all select 5, 'e', 'ee'
union all select 6, 'f', 'ff'
select * from (select top 2 * from @ta order by ID desc )ta order by id asc(6 行受影响)
ID name Content
----------- ---- -------
5 e ee
6 f ff(2 行受影响)
insert @ta select 1, 'a', 'aa'
union all select 2, 'b', 'bb'
union all select 3, 'c', 'cc'
union all select 4, 'd', 'dd'
union all select 5, 'e', 'ee'
union all select 6, 'f', 'ff'
select * from @ta where id not in (select top 4 id from @ta )--如果id是递增时可以这样用(6 行受影响)
ID name Content
----------- ---- -------
5 e ee
6 f ff(2 行受影响)