使用 desc 后 SQL Server 逆序 [英] SQL Server reverse order after using desc
本文介绍了使用 desc 后 SQL Server 逆序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在使用 desc 后颠倒 SQL Server 中的结果顺序.例如:
I want to reverse the order in SQL Server of results after using desc. For example:
SELECT TOP 3 * FROM table ORDER BY id DESC
返回结果:
505
504
503
但是我想把结果翻转成这样:
But then I want to flip the results to look like this:
503
504
505
我试过了
SELECT * FROM (SELECT TOP 3 * FROM table ORDER BY id DESC) ORDER BY id ASC
但这没有用.我该如何解决?
But that did not work. How can I fix it?
推荐答案
只要您为子查询设置别名,这应该有效.
That should work as long as you alias the subquery.
SELECT q.*
FROM (SELECT TOP 3 *
FROM table
ORDER BY id DESC) q
ORDER BY q.id ASC
这篇关于使用 desc 后 SQL Server 逆序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文