how to get second highest salary department wise without using analytical functions?

前端 未结 11 2020
孤独总比滥情好
孤独总比滥情好 2021-01-06 03:08

Suppose we have 3 employees in each department.we have total 3 departments . Below is the sample source table

Emp deptno salary
A    10     1000
B    10              


        
11条回答
  •  耶瑟儿~
    2021-01-06 04:08

    Solution using Correlated Subquery:

    SELECT * FROM emp e1 WHERE 2 = (SELECT COUNT(DISTINCT sal)
                                      FROM emp e2 
                                     WHERE e1.sal <= e2.sal
                                       AND e1.deptno = e2.deptno
                                   );
    

提交回复
热议问题