从表中找出第n高的薪水 [英] Find out the nth-highest salary from table

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

问题描述

name   salary
-----   -----
mohan     500
ram      1000
dinesh   5000
hareesh  6000
mallu    7500
manju    7500
praveen 10000
hari    10000

如何使用Oracle从上述表格中找到第n高的薪水?

How would I find the nth-highest salary from the aforementioned table using Oracle?

推荐答案

您可以使用类似的方法.这是我测试过的内容,然后粘贴到此处

you can use something like this.. this is what i have tested and then pasted here

SELECT *
FROM   tblname
WHERE  salary = (SELECT *
                 FROM   (SELECT *
                         FROM   (SELECT *
                                 FROM   (SELECT DISTINCT( salary )
                                         FROM   tblname
                                         ORDER  BY salary DESC) A
                                 WHERE  rownum <= nth) B
                         ORDER  BY salary ASC) C
                 WHERE  rownum <= 1) 

'tblname'代替您的表名,然后用 nth 替代您想要的第n个最高薪水

in place of 'tblname' give your table name and then in place nth give your desired nth highest salary that you want

您可以在屏幕快照中看到它正在工作.

you can see in the screen shot that it is working.

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

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