Write LINQ query to find 2nd highest salary?
OR
Write LINQ query to find nth highest salary?
Ans. You can find nth highest salary by writing the following query.
DataContext context = new DataContext();
var q= context.tblEmployee.GroupBy(ord => ord. Salary)
.OrderByDescending(f => f.Key)
.Skip(1) //second, third ..nth highest salary where n=1,2...n-1
.First()
.Select(ord=>ord. Salary)
.Distinct();
OR
Write LINQ query to find nth highest salary?
Ans. You can find nth highest salary by writing the following query.
DataContext context = new DataContext();
var q= context.tblEmployee.GroupBy(ord => ord. Salary)
.OrderByDescending(f => f.Key)
.Skip(1) //second, third ..nth highest salary where n=1,2...n-1
.First()
.Select(ord=>ord. Salary)
.Distinct();
Comments
Post a Comment