在MYSQL中排名第七

0yg35tkg  于 2022-11-21  发布在  Mysql
关注(0)|答案(4)|浏览(147)

如何在MySQL的员工表中找到第七高工资的行?我试过这种方法,但无法得到准确的查询。

SELECT MAX(salary) FROM employee 
WHERE salary NOT IN 
      (SELECT MAX(salary) FROM employee)
06odsfpq

06odsfpq1#

多么简短的帖子!!!试试这个,

select *
from(
    select distinct salary
    from employee
    order by salary desc limit 7
) t
order by salary
limit 1
wj8zmpe1

wj8zmpe12#

也许你可以用这个

SELECT * FROM employe ORDER BY salary DESC LIMIT 7

我希望这对你有帮助

r6l8ljro

r6l8ljro3#

我知道答案了。

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

r7knjye24#

SELECT *
FROM employees emp
WHERE 7 =
    (SELECT COUNT(DISTINCT salary)
     FROM employees
     WHERE emp.salary<=salary );

相关问题