这样的sql语句如何转换成linq语法

yaojunyi3721 2014-04-07 02:53:08
一。对于EMPLOYEES中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序select count(*) as 员工数,a.DEPARTMENT_ID as 部门号,avg(SALARY) as 平均工资 from EMPLOYEES as a
where (select count(c.EMPLOYEE_ID) from EMPLOYEES as c where c.DEPARTMENT_ID = a.DEPARTMENT_ID and c.SALARY>(select avg(SALARY) from EMPLOYEES as b where c.DEPARTMENT_ID = b.DEPARTMENT_ID))>1
group by a.DEPARTMENT_ID order by a.DEPARTMENT_ID
二。对于EMPLOYEES中低于自己工资至少5人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数
select a.DEPARTMENT_ID,a.EMPLOYEE_NAME,a.SALARY,(select count(*) from EMPLOYEES as b
where b.SALARY < a.SALARY) as 人数 from EMPLOYEES as a
where (select count(*) from EMPLOYEES as b where b.SALARY<a.SALARY)>=5

要求尽量使用查询语法即非拉姆达表达式的方式 尽量减少分段数即能一个长查询查完的不分多段用多个var类型变量
...全文
98 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaojunyi3721 2014-04-07
  • 打赏
  • 举报
回复
附上建表语句 方便大家测试 create database MyCompany go use MyCompany go create table Departments ( Department_ID int identity(1,1) primary key, Department_Name nvarchar(50), ) go create table Employees ( Employee_Id int identity(1,1) primary key, Employee_Name nvarchar(50), Employee_Job nvarchar(50), Salary money, Department_Id int foreign key references Departments(Department_ID) ) go insert into Departments values('财务部') insert into Departments values('行政部') insert into Departments values('开发部') insert into Employees values('曹操','组长',20000,3) insert into Employees values('刘备','经理',30000,3) insert into Employees values('诸葛亮','CEO',10000,2) insert into Employees values('黄月英','职员',5000,1) insert into Employees values('关羽','职员',8000,3) insert into Employees values('张飞','职员',8000,3) insert into Employees values('赵云','职员',7000,3) insert into Employees values('马谡','职员',4000,3)

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧