我想在我的课程管理系统中创建讲师的每月出勤报告。在此报告中,我需要使用嵌套选择查询来计算讲师在场和缺席的数量,以便在特定记录中显示它们。我认为可能的方法是,如果讲师代码与主查询中正在处理的讲师代码相同,则对要计算的每个出勤状态使用选择语句!
select lecturers.*, sum(distinct courses.credit) as 'Due Credits',(select count(*) from attendances where status='1' ) as Present, (select count(*) from attendances where status='0' ) as Absent from lecturers,courses,attendances
where attendances.lecturer_code=lecturers.code
AND courses.lecturer_code=lecturers.code
group by lecturer_code
【代号、姓名、部门、职务、学历为固定属性】
我需要知道是否有更好的方法来做到这一点!
非常感谢!