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

前端 未结 11 2014
孤独总比滥情好
孤独总比滥情好 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 03:51

    This will give you 2nd highest salary in each department:

    SELECT a.Emp, a.deptno, a.salary
    FROM Emp a
    WHERE 1 = (SELECT COUNT(DISTINCT salary) 
            FROM Emp b 
            WHERE b.salary > a.salary AND a.deptno = b.deptno)
    group by a.deptno
    

提交回复
热议问题