如何找到第二高薪 [英] how to find 2nd highest pay

查看:56
本文介绍了如何找到第二高薪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名称为
的表 tbPay

现在有很多不同净额的工资
现在我只想获得第二高的薪水金额.

I have a table with name
tbPay

Now there are alot of pays with differnet amount
Now i want to get the 2nd highest pay amount only.

推荐答案

看这篇文章:http://blog.sqlauthority.com/2008/04 /02/sql-server-find-nth-nest-salary-of-employee-query-to-retrieve-the-nth-maximum-value/ [
Look at this article: http://blog.sqlauthority.com/2008/04/02/sql-server-find-nth-highest-salary-of-employee-query-to-retrieve-the-nth-maximum-value/[^]

SELECT
    TOP 1 salary
FROM
    (SELECT DISTINCT TOP 2 salary FROM tbPay ORDER BY salary DESC) a ORDER BY salary


尝试:
WITH Results as
   (SELECT Row_Number() over (ORDER BY Salary DESC) as RN,* FROM tbPay)
SELECT * FROM Results WHERE RN=2


尝试以下查询.
salary是包含员工薪水的列,而tbPay是包含员工记录的表的名称.

Try the following query.
The salary is the column which contains the employees salary and the tbPay is the name of the table which has the records of the employees.

SELECT MAX(salary) FROM tbPay WHERE salary NOT IN (SELECT MAX(salary) FROM tbPay)



这有帮助吗?



Does this help?


这篇关于如何找到第二高薪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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