Find 2nd max salary using linq

前端 未结 6 540
执笔经年
执笔经年 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条回答
  •  梦毁少年i
    2021-01-02 08:11

    Using LINQ, you can find the 3rd highest salary like this:

    // first use LINQ to sort by salary, then skip first 2 and get next
    var thirdHighestSalary= (from n in db.Employee order by n.salary descending select n).distinct().skip(2).  FirstOrDefault()
    // write the result to console
    Console.WriteLine(Third Highest Salary is : {0},thirdHighestSalary.Salary);
    

提交回复
热议问题