Find 2nd max salary using linq

前端 未结 6 542
执笔经年
执笔经年 2021-01-02 07:47

I have following sql query for finding 2nd max salary.


Select * From Employee E1 Where
    (2) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where
               


        
6条回答
  •  庸人自扰
    2021-01-02 08:10

    This will work for duplicate record as well as nth highest salary just need to play with take and skip thats all for ex below is for 3 rd highest salary with duplicate record present in table-

    emplist.OrderByDescending(x => x.Salary).Select(x=>x.Salary).Distinct().Take(3).Skip(2).First();
    

提交回复
热议问题