我正在开发一个跟踪培训的基于网络的应用程序
为公司的每位员工。我有以下数据库
设计
Employee Table: Username, Name, DivisionCode
Division Table: SapCode, DivisionName
Course Table: CourseID, CourseName, GroupID
Group Table: GroupID, GroupName
Employee_Course Table: Username, CourseID
(每个表中的第一个属性是除最后一个表之外的主键)
我有来实现一个图表或表格,显示这些课程每门课程中每个部门的完成百分比,但我不知道如何提出这个查询。查询应显示DivisionName,CourseName,每个课程中的参与者数量和完成百分比
那么请你帮我解决一下这个问题吗?
答案 0 :(得分:0)
select a.DivisionName, a.CourseName, a.ParticipantsCount, ParticipantCount / EmployeeCount * 100 as PercentCompleted
from (
select DivisionName, count(*) as EmployeeCount
from Division d
inner join Employee e on d.DivisionCode = e.DivisionCode
group by DivisionName
) dc
inner join (
select d.DivisionName, c.CourseName, count(*) as ParticipantCount
from Course c
inner join Employee_Course ec on c.CourseID = ec.CourseID
inner join Employee e on ec.Username = e.Username
inner join Division d on e.DivisionCode = d.DivisionCode
group by DivisionName, CourseName
) a on dc.DivisionName = a.DivisionName