可以一起使用Rank函数和WHERE吗? [英] Possible to use Rank function and WHERE together?

查看:164
本文介绍了可以一起使用Rank函数和WHERE吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是SQL的新手。我的问题是



是否可以一起使用 Rank 功能和 Where ?如果是的话,你能给出一个例子。



我正在尝试从示例数据库中检索第三高薪员工。



提前谢谢

Hi,

I''m a newbie to SQL. My Question is

Is it possible to use Rank function and Where together? If yes, can you give an example.

I''m trying to retrieve the 3rd highest paid employee from a sample database.

Thanks in advance

推荐答案

可以给出这里 [ ^ ]。



以下是使用的示例 -

it is possible as given here[^].

Here is the example used -
USE AdventureWorks2012
SELECT TOP(10) BusinessEntityID, Rate, 
       RANK() OVER (ORDER BY Rate DESC) AS RankBySalary
FROM HumanResources.EmployeePayHistory AS eph1
WHERE RateChangeDate = (SELECT MAX(RateChangeDate) 
                        FROM HumanResources.EmployeePayHistory AS eph2
                        WHERE eph1.BusinessEntityID = eph2.BusinessEntityID)
ORDER BY BusinessEntityID;


In T -sql你可以轻松使用Rank fu与此处 [ ^ ]。
In T-sql you can easily use Rank function with WHERE clause as given here[^] in MSDN.


这篇关于可以一起使用Rank函数和WHERE吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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