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

前端 未结 8 1438
不思量自难忘°
不思量自难忘° 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:46

    Simplest Implementation,

     (select * from tbl_salary order by salary desc limit 5) order by salary limit 1;
    
    
     (select * from tbl_salary order by salary desc limit 2) order by salary limit 1;
    
    0 讨论(0)
  • 2021-02-20 08:48

    // for highest salary of table

    select salary from table order by salary desc limit 0,1
    

    // for second highest salary

    select salary from table order by salary desc limit 1,1
    

    Using this query you get nth number of salary from table....

    0 讨论(0)
提交回复
热议问题