Find 2nd max salary using linq

前端 未结 6 558
执笔经年
执笔经年 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

    public class Program
    {
        public static void Main()
        {
            IList intList = new List() { 10, 21, 91, 30, 91, 45, 51, 87, 87 };
    
            var largest = intList.Max();
    
            Console.WriteLine("Largest Element: {0}", largest);
    
            var secondLargest = intList.Max(i => {
                if(i != largest)
                    return i;
                return 0;
            });
    
            Console.WriteLine("second highest element in list: {0}", secondLargest);
        }
    }
    

提交回复
热议问题