题目
原文:
Write a method to find the number of employees in each department.
译文:
写一个SQL语句找出在每个部门的员工的数量。
解答
这个问题可以将部门表与员工表做连接,然后统计每个部门的员工数。注意是使用左连接,而不是内连接,因为要包含员工数为0的部门。
select Dept_Name, Departments.Dept_ID,
count(*) as ‘num_employees‘
from Departments
left join Employees
on Employees.Dept_ID = Departments.Dept_ID
group by Departments.Dept_ID,
Dept_Name
相关SQL语句练习的资料:http://www.jfox.info/yuan-gong-bu-men-gong-zi-sql-mian-shi-ti
http://blog.csdn.net/zbdba/article/details/16806937
---EOF---
Cracking the coding interview--Q15.1,布布扣,bubuko.com
Cracking the coding interview--Q15.1
原文:http://blog.csdn.net/navyifanr/article/details/21691997