34,588
社区成员
发帖
与我相关
我的任务
分享
-- 4.1
select '员工名称'=a.name,
'部门名称'=b.name
from [Users] a
inner join [Depts] b on a.dept_id=b.id
order by b.order_code,a.order_code
-- 4.2
select '部门名称'=b.name,
'员工ID'=a.id,
'员工名称'=a.name,
'员工工资'=a.salary
from [Users] a
inner join [Depts] b on a.dept_id=b.id
where not exists(select 1
from [Users] c
where c.dept_id=a.dept_id
and c.salary>a.salary)
order by b.order_code
-- 4.3
select '部门名称'=b.name,
'员工数量'=count(1)
from [Users] a
inner join [Depts] b on a.dept_id=b.id
where a.salary>4000
group by b.id,b.name