首页 > 其他 > 详细

Cracking the coding interview--Q15.1

时间:2014-03-21 11:01:35      阅读:487      评论:0      收藏:0      [点我收藏+]

题目

原文:

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!