SQL怎样把查出来的结果集再倒序查询?
有一张表tableID:s_id12345678910现在想得到54321这样的结果集.用selecttop5s_idfromtableIDorderbys_iddesc...
有一张表tableID:
s_id
1
2
3
4
5
6
7
8
9
10
现在想得到5 4 3 2 1这样的结果集.
用select top 5 s_id from tableID order by s_id desc得到的结果是10 9 8 7 6
用select top 5 s_id from (select top 5 s_id from tableID) as T order by s_id desc得到的结果集还是10 9 8 7 6
如果用in子查询很简单,但是题目要求不能用!有高手能指教下不?
同时不能用> <号 展开
s_id
1
2
3
4
5
6
7
8
9
10
现在想得到5 4 3 2 1这样的结果集.
用select top 5 s_id from tableID order by s_id desc得到的结果是10 9 8 7 6
用select top 5 s_id from (select top 5 s_id from tableID) as T order by s_id desc得到的结果集还是10 9 8 7 6
如果用in子查询很简单,但是题目要求不能用!有高手能指教下不?
同时不能用> <号 展开
4个回答
展开全部
if object_id('tb') > 0 drop table tb
go
create table tb (sid int)
insert into tb 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'
select * from (select top 5 * from tb) t
order by t.sid desc
楼主直接给分吧、哈哈!
go
create table tb (sid int)
insert into tb 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'
select * from (select top 5 * from tb) t
order by t.sid desc
楼主直接给分吧、哈哈!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select T.s_id from (select top 5 s_id from tableID order by s_id ) as T order by T.s_id desc
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * from (select top 5 s_id from tableID order by s_id ) aa order by s_id desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Order by ...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询