我有以下数据库设计:
Employees Table: EmployeeID, Name, OrgCode
Departments Table: OrgCode, DepatName
CompleteSurvey Table: ID, ParticipantID
我需要开发一个表格,显示每个部门的员工总数,以及每个部门完成调查的参与者总数。然后,我想显示每个部门的参与百分比,主要等于参与者总数/员工总数。
我提出了以下两个查询,但我必须提出一个显示上述要求的查询,那么该怎么做呢?
各部门员工总数:
SELECT COUNT(DISTINCT dbo.Employees.EmployeeID) AS [Total Number of Employees],
dbo.Departments.DepartmentName
FROM dbo.Departments
INNER JOIN dbo.Employees ON dbo.Departments.OrgCode = dbo.Employees.OrgCode
GROUP BY dbo.Departments.DepartmentName
各部门总人数:
SELECT COUNT(DISTINCT dbo.Employees.EmployeeID) AS [Total Number of Employees],
dbo.Departments.DepartmentName
FROM dbo.Departments
INNER JOIN dbo.Employees ON dbo.Departments.OrgCode = dbo.Employees.OrgCode
INNER JOIN dbo.CompleteSurvey ON dbo.Employees.EmployeeID = dbo.CompleteSurvey.RespondantID
GROUP BY dbo.Departments.DepartmentName
显示参与者的第二个查询的问题,即使没有参与者,它也不会显示所有部门,它应该显示零。
更新:
基本上,我想要的是有一个查询,显示每个部门的员工总数和每个部门完成调查的参与者总数,并显示参与百分比。