在MySQL中无限制地找到第三高的薪水 [英] finding the 3rd highest salary in mysql without limit

查看:119
本文介绍了在MySQL中无限制地找到第三高的薪水的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在不使用限制的情况下找到一张桌子的第三高薪水.

i have been trying to find the 3rd highest salary of a table without using limit.

在我使用第二高薪的情况下

In case of 2nd highest salary i use

SELECT salary FROM table WHERE salary < ( SELECT MAX( salary ) order by salary desc

找到我使用的极限值第三高的

to find the 3rd highest with limit i use

select salary from one order by salary desc limit 3,1

现在如何在不使用限制的情况下找到第n个薪水?

now how to find nth salary without using limit?

推荐答案

尝试此查询,

   SELECT *
   FROM one one1
   WHERE ( 3 ) = ( SELECT COUNT( one2.salary )
                   FROM one one2
                   WHERE one2.salary >= one1.salary
                 )

哪里(n),您可以输入任意数字以返回最高薪水.

Here WHERE ( n ) yo can put any number to return that highest salary.

选中此 演示SQLFiddle

这篇关于在MySQL中无限制地找到第三高的薪水的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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