Tuesday, 15 March 2011

sql - Select the salary of the higher-paid employees of the manager -



sql - Select the salary of the higher-paid employees of the manager -

i have table:

create table emp ( empno int identity(1,1) primary key, ename nvarchar(350), job nvarchar(100), mgr int, hiredate datetime, sal int, comm int, deptno int )

i want select salary of higher-paid employees of manager.

here's code:

from in emps ((from b in emps b.mgr != null select b.sal + (b.comm != null ? b.comm :0))) > (select c in emps c.mgr == null select b.sal +(b.comm != null ? b.comm :0)) select a.ename

please! help me.

i think looking employees paid highest salary under each manager. if case, seek this:-

var query = employees.groupby(x => x.managername) .select(x => new { managername = x.key,employeename = x.orderbydescending(z => z.salary + (z.comm ?? 0)).first().empname });

step 1: grouping managername step 2: select managername (which key after grouping), each grouping fetch highest paid employee ordering in descending order , selecting first employee.

where have used type:-

public class employee { public int empid { get; set; } public string empname { get; set; } public string managername { get; set; } public decimal salary { get; set; } public int? comm { get; set; } }

fiddle.

sql linq

No comments:

Post a Comment