34,587
社区成员
发帖
与我相关
我的任务
分享
declare @A table(id int)
insert @A
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 12 union all
select 13 union all
select 14 union all
select 15
select * from
(
select top 10 * from @A-- order by id
) as a
order by id desc
/*
id
10
9
8
7
6
5
4
3
2
1
*/
select id from
(
select top 10 id from a order by id
) as a
order by id desc
select top 10 id from a order by id desc
/*上面是先排序后再取前10条,如果下面是先正序取10,再倒序排序,如果去掉里面的order by id ASC,则也是先排序后再取前10条*/
select * from (select top 10 * from @A order by id ASC) as A order by A.id desc