Sql server 第三高薪部门,不使用职级或其他职能

Sql server 第三高薪部门,不使用职级或其他职能,sql-server,database,Sql Server,Database,我希望在不使用sql中的任何函数(如rank或row\u number或densite\u 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 dep

我希望在不使用sql中的任何函数(如
rank
row\u number
densite\u 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 
这是我的查询。语法是正确的,但它没有给出答案/结果

这应该可以解决问题

select salary, deptno from emp e where 2 = 
(select count(distinct salary) from emp where
salary > e.salary and deptno = e.depto) 
使用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

是否允许交叉应用
?您的查询不完整:
部门分组是
,您是否可以改写您的问题?现在还不清楚你想要什么,你还没有明确说明你想要的是第三高的薪水还是第三高的薪水。领带很重要。你为什么不想使用窗口功能呢?它们是解决此类问题的完美工具。