select d.departmentid,
departmentname,
ds.amount,
ds.avgsal
from departments d,
(select departmentid,
count(*) amount,
avg(salary) avgsal
from employees
group by departmentid) ds
where d.departmentid = ds.departmentid
departmentname,
ds.amount,
ds.avgsal
from departments d,
(select departmentid,
count(*) amount,
avg(salary) avgsal
from employees
group by departmentid) ds
where d.departmentid = ds.departmentid
本文展示了一个SQL查询语句,用于获取部门ID、对应部门名称、员工总数以及该部门员工的平均薪资。通过联接两个表(departments和employees),并使用聚合函数COUNT和AVG,实现对数据的高效提取。
4735

被折叠的 条评论
为什么被折叠?



