-1

我想在不使用 sql 之类的rank任何函数的情况下明智地找到第三高薪部门我的逻辑row_numberdense_rank

select max(salary),deptno from emp
where salary not in
(select max(salary) from emp where salary not in
(select max(salary) from emp group by deptno)group by deptno)
group by deptno 

这是我的查询。语法是正确的,但它没有给出正确的答案/结果

4

2 回答 2

1

这应该做的工作

select salary, deptno from emp e where 2 = 
(select count(distinct salary) from emp where
salary > e.salary and deptno = e.depto) 
于 2013-09-05T16:28:34.713 回答
0

使用 MSSQL,

SELECT MAX(salary) as '3rdHighest', deptno
FROM EMP n WHERE 2 = 
                      (SELECT COUNT(DISTINCT salary) FROM NewTbl 
                        WHERE salary > n. salary and deptno = n.deptno) 
GROUP BY deptno
于 2018-12-04T20:33:07.230 回答