1

我有一张缺勤表,那张表存储着缺勤人员的学生证。

从这个表中我必须找到总出席者和总缺席者,为此我刚刚加入了包含特定部分最大容量的部分表。

为此,我的查询是

select COUNT(Attendance.studentid) as Absentees
        ,Sections.Max-count(studentid) as Presentees
from Attendance
inner join Students
on students.StudentId=Attendance.StudentId
inner join Sections
on Sections.CourseId=students.CourseId
group by Sections.Max

它工作正常,同样我如何找到性别明智的出席者/缺席者......性别列在学生表中,任何人都可以给我一些想法,提前谢谢

4

1 回答 1

5

只需将性别列添加到您的select ...列和 中group by,您最终将得到每个性别的一行:

select COUNT(Attendance.studentid) as Absentees,
       Sections.Max-count(studentid) as Presentees,
       Students.Gender as Gender
from Attendance
inner join Students
on Students.StudentId=Attendance.StudentId
inner join Sections
on Sections.CourseId=Students.CourseId
group by Sections.Max, Students.Gender
于 2012-04-12T06:56:06.623 回答