看起来像下面的表格
如何编写 SQL 查询以读取员工计数工资 > 1000 的所有部门名称,如果在员工中找不到部门,我们需要在输出中显示为零计数。
您可以使用left join和聚合:
left join
select d.name, count(e.id) from departments d left join employees e on e.department_id = d.id and e.salary >= 10000 group by d.name
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
点击生成二维码
我来说两句