我有以下数据库设计:
Employee Table: Username, Name, DivisionCode
Division Table: SapCode, DivisionShortcut
Courses Table: CourseID, CourseName, GroupID
Groups Table: GroupID, GroupName
Employee_Courses Table: EmployeeID, CourseID
我提出了以下查询,显示了部门、课程和每个部门的参与者总数:
SELECT dbo.Divisions.DivisionShortcut, dbo.courses.CourseName, COUNT(dbo.employee_courses.courseId) AS [Total Number of Participants]
FROM dbo.courses INNER JOIN
dbo.employee_courses ON dbo.courses.CourseID = dbo.employee_courses.courseId INNER JOIN
dbo.groups ON dbo.courses.GroupID = dbo.groups.ID RIGHT OUTER JOIN
dbo.employee AS employee_1 INNER JOIN
dbo.Divisions ON employee_1.DivisionCode = dbo.Divisions.SapCode ON dbo.employee_courses.employeeId = employee_1.Username
WHERE (dbo.courses.GroupID = 1)
GROUP BY dbo.courses.CourseID, dbo.courses.CourseName, dbo.Divisions.DivisionShortcut
除了上面显示的之外,我还想显示每个部门的员工总数和每个部门的完成百分比。顺便说一句,完成百分比等于(每个课程的参与者总数/每个部门的员工总数)
那么该怎么做呢?