How to find n'th highest value of a column?

前端 未结 8 1557
不思量自难忘°
不思量自难忘° 2021-02-20 07:56

Is there a command akin to:

  • 2nd highest salary from tbl_salary or

  • 4th highest salary from tbl_salary ?

8条回答
  •  一向
    一向 (楼主)
    2021-02-20 08:40

    Here is a very simple way to get the result of n'th highest value

    put n=2 to get second highest salary
    pur n=4 to get fourth highest salary
    and so on...

    Here is query
    if n=2

    select salary from tbl_salary e1
    where 2 = (
    select distinct(count(salary))
    from tbl_salary e2
    where e1.salary< e2.salary
    )
    

    Best luck

提交回复
热议问题