已知某 MySQL 数据库中,有表及其字段如下: Employee(员工)表,字段:ID(标识,主键)、Name(姓名)、DepartmentID(班级标识,外键) Department(部门)表,字段:ID(标识,主键)、Name(名称) 要查询各部门人数(包括空部门),可以使用的查询语句是:
已知某 MySQL 数据库中,有表及其字段如下: Employee(员工)表,字段:ID(标识,主键)、Name(姓名)、DepartmentID(班级标识,外键) Department(部门)表,字段:ID(标识,主键)、Name(名称) 要查询各部门人数(包括空部门),可以使用的查询语句是:
A.SELECT Department.Name, COUNT(Employee.ID) '班级人数' FROM Department RIGHT JOIN Employee WHERE Department.ID = Employee.DepartmentID GROUP BY Department.Name, Employee.DepartmentID
B.SELECT Department.Name, COUNT(Employee.ID) '班级人数' FROM Department RIGHT JOIN Employee ON Department.ID = Employee.DepartmentID GROUP BY Department.Name, Employee.DepartmentID
C.SELECT Department.Name, COUNT(Employee.ID) '班级人数' FROM Department LEFT JOIN Employee WHERE Department.ID = Employee.DepartmentID GROUP BY Department.Name, Employee.DepartmentID
D.SELECT Department.Name, COUNT(Employee.ID) '班级人数' FROM Department LEFT JOIN Employee ON Department.ID = Employee.DepartmentID GROUP BY Department.Name, Employee.DepartmentID
正确答案:D