SQL最高价值相反 [英] SQL Top Value opposite

查看:169
本文介绍了SQL最高价值相反的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

TOP是否与之相反,如最低值或最新值.


谢谢
最好的问候.

Hey there,

Is there an opposite to TOP , something like a Least Value or latest value.


Thank You
Best Regards.

推荐答案

仅使用TOP,但将排序顺序从ASC更改为DESC.

无论如何,TOP仅在您使用ORDER BY子句时才有意义,因为不需要DB以其他特定顺序返回记录.
Just use TOP, but change the sort order to DESC from ASC.

TOP only makes sense when you use an ORDER BY clause anyway, as the DB is not required to return records in any particular order otherwise.


基于对话,如果我正确理解了您的问题,您可以使用内联视图.但是,在跳转到SQL之前,我建议您仔细阅读一下sql语句和/或表结构,因为听起来好像应该更正它们.

无论如何,请考虑以下
Bases on the conversation if I understood your question correctly, you can possibly use inline views. However, before jumping to the SQL, I would suggest going through your sql statement and/or table structure since it sounds like they should be corrected.

Anyhow, consider the following
select top 5 name
from (select name 
      from (select top 100 percent name 
            from sysobjects 
            order by name) as a
      union all
      select name 
      from (select top 100 percent name 
            from syscolumns 
            order by id) as b) as c
order by name desc


这篇关于SQL最高价值相反的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆