我有这张桌子
EMPs(EmpNo int primary key identity(001,1),
Ename nvarchar(50),
Job nvarchar(20),
Mgr int,
HireDate datetime,
Sal int,
Comm int,
DeptNo)
我想选择排名前3的HiSal?
(from a in EMPs
group a by true into r
select r.OrderByDescending(x => x.Sall +(x.Comm != null ? x.Comm :0))).Take(3)
答案 0 :(得分:3)
看起来你的订单最多(薪水+佣金)至少,然后尝试选择前三名。
我认为你让它变得比你更复杂。试试这个:
var top3salaries = EMPs.OrderByDescending(x => x.Sal + x.Comm).Take(3);
您的查询还显示佣金可以是null
。如果是这样的话:
var top3salaries = EMPs.OrderByDescending(x => x.Sal + (x.Comm ?? 0)).Take(3);
答案 1 :(得分:-2)
尝试此查询:
select top(3) EName, MAX(salary) as Hisal
from EMPLOYEES
group by EMPLOYEE_ID
order by MAX(salary) desc