У меня есть следующая сущность
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string Department { get; set; }
public long Salary { get; set; }
}
Я пытаюсь найти вторую наивысшую зарплату для сотрудников каждого отдельного отдела, использующего LINQ.
Пока что вот что у меня естьсделано
var Query = (from emp in Employees
orderby emp.Salary descending
group emp by emp.Department into g
select new
{
id = g.Select(i=>i.EmployeeID),
sal = g.Select(s=>s.Salary),
name = g.Select(n=>n.EmployeeName),
dept = g.Select(d=>d.Department)
}
).Skip(1).ToList();
Но этот запрос не работает.,
Например
Предположим, у меня есть
EmployeeID = 1,EmployeeName ="A", Department ="Dept1", Salary = 10000
EmployeeID = 2,EmployeeName ="B", Department ="Dept1", Salary = 20000
EmployeeID = 3,EmployeeName ="C" Department ="Dept1", Salary = 20000
EmployeeID = 4,EmployeeName="D", Department ="Dept1", Salary = 30000
EmployeeID = 5,EmployeeName ="A1", Department ="Dept2", Salary = 12000
EmployeeID = 6,EmployeeName ="B1", Department ="Dept2", Salary = 4500
Ожидаемый результат будет
EmployeeID = 2,EmployeeName ="B", Department ="Dept1", Salary = 20000
EmployeeID = 3,EmployeeName ="C" Department ="Dept1", Salary = 20000
EmployeeID = 6,EmployeeName ="B1", Department ="Dept2", Salary = 4500
в наборе результатов
Использование C # 3.0 и Dotnet framework 3.5