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

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

    Very simple logic.

    Please try:

    SELECT dept as dd, ( SELECT ee.salary FROM `employees` as ee WHERE ee.dept=dd 
    ORDER BY ee.salary DESC LIMIT 1,1 ) as sndHigh 
    FROM `employees` 
    WHERE 1 
    GROUP BY dept
    

提交回复
热议问题